;
(function () {
  var planDataList = []
  new Vue({
    el: '#contract_create_2',
    data() {
      return {
        permissions: JSON.parse(localStorage.getItem('permissions')),
        contractId: hlUrlUtil.GetQueryString('id'),
        getCtPrevData: JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_FIRST_STEP')), // 获取缓存数据
        signingDate: '', //签订日期
        beginDate: '', //租赁期限（开始）
        endDate: '', //租赁期限（结束）
        timeList: {
          list: [{
            name: '季度',
            code: 0.3
          }, {
            name: '半年',
            code: 0.6
          }, {
            name: '1年',
            code: 1
          }, {
            name: '2年',
            code: 2
          }, {
            name: '3年',
            code: 3
          }, {
            name: '4年',
            code: 4
          }, {
            name: '5年',
            code: 5
          }],
          active: [],
        }, //快捷选择
        billDate: {
          BFList: [{
            name: '账单开始前',
            code: 'B'
          }, {
            name: '账单开始后',
            code: 'A'
          }],
          BFCode: ['B'],
          dayList: [{
            name: '固定天数',
            code: 'TS'
          }, {
            name: '固定日期',
            code: 'RQ'
          }],
          dayCode: ['TS'],
          naturalDay: '1',
        }, //收款日
        SQdate: '', //首期付款日
        /////////////////////////////////////////////////////////////////////////////固定租金板块
        isGDZJflag: false,
        setRent: {
          list: [{
            name: '按固定租金',
            code: 'M'
          }, {
            name: '按实际天数',
            code: 'D'
          }],
          active: ['M']
        },
        setUnit: {
          one: {
            list: [{
              name: '元/平米/天',
              code: '0'
            }, {
              name: '元/平米/月',
              code: '1'
            }]
          },
          two: {
            list: [{
              name: '元/个/天',
              code: '0'
            }, {
              name: '元/个/月',
              code: '1'
            }]
          },
          nIndex: ['0'],
          active: 'one'
        },
        rentProperty: '', //租金计算周期
        rentBill: {
          oPrice: '', //租金单价
          dRent: '', //日租金
          mRent: '', //月租金
          pay: '', //付款周期
          rentPercent: '', //租金滞纳金比例
          bet: '', //押
          menoy: '', //押金
          proportion: '', //押金滞纳金比例
          day: '' //
        },
        oPrice: '', //租金单价(展示)
        dRent: '', //日租金（展示）
        mRent: '', //月租金（展示）
        menoy: '', //押金金额（展示）
        monthRentPriceAlert: '',
        dayRentPriceAlert: '',
        ////////////////////////////////////////////////////////////////////////////////押金板块
        isYJflag: false,
        //////////////////////////////////////////////////////////////////////////////// 阶梯租金
        ladderRentArr: [], //递增时间
        ladderRentActive: [],
        rentLadder: [], //阶梯租金列表（小数保留两位）
        copyRentLadderArr: [], //阶梯租金列表（小数保留4位）
        /////////////////////////////////////////////////////////////////////////////// 免租期
        freePeriod: [],
        /////////////////////////////////////////////////////////////////////////////// 营业额抽成
        isYYECCflag: false,
        turnoverArr: [],
        turnoverCode: ['FD'],
        turnoverCheckBox: 'N', //租金取其高
        tableArr: [{
          base_val_down_limit: '0',
          base_val_up_limit: '',
          commission_percent: '',
          commission_down_limit: '',
          commission_up_limit: '',
          late_fee_percent: ''
        },],
        paymentType: [{
          name: '同租赁周期',
          code: 'BL',
        }, {
          name: '自选日期',
          code: 'CM',
        }],
        paymentTypeCode: ['BL'],
        billDateQH: [{
          name: '账单开始前',
          code: 'B',
        }, {
          name: '账单开始后',
          code: 'A'
        }],
        billDateQHcode: 'B',
        billDay: [{
          name: '固定天数',
          code: 'TS'
        }, {
          name: '固定日期',
          code: 'RQ'
        }],
        billDaycode: 'TS',
        dayNum: '',
        paymentCycle: '', //付款周期
        ////////////////////////////////////////////////////////////////////////////// 周期性费项
        cTData_P: [], //费项类型列表(周期性)
        isZQXFXtimeFlag: false,
        setZXQFXtimeList: [], //编辑当前费项的计算周期
        /////////////////////////////////////////////////////////////////////////////一次性费项
        cTData_O: [], //费项类型列表(一次性)
        //////////////////////////////////////////////////////////////////////////////公共部分
        costItem: [],
        cTIndex: '', //编辑周期性名称的哪一条下标
        isPayBillFlag: false, //展示付款计划
        haveGDflag: false, //是否有固定租金板块
        haveYJflag: false, //是否有押金板块
        haveYYECCflag: false, //是否有营业额板块
        resData: [],
        payData: [],
        intentDeductibleAmount: 0,
        ePayData: {},
        payplanData: {},
        TemplateModulShow: false,
        rentDepositFlag: true,
        TemTypeList: ['Word', 'PDF'],
        selectedTemTypeList: [],
        temList: [],
        selectedTemList: '',
        TemplateModulShow: false,
        contractDetail: '',
        reletFlag: hlUrlUtil.GetQueryString('relet'),
        atAges: 0,
        wpNums: 0,
        expenditureUnit: [], //费项计量单位
        commissionStatus: '', //合同中体现中介佣金flag
        intermediaryCommission: '', //中介佣金金额（元）
        intermediaryCommission4: '', //中介佣金金额（元）
        intermediaryCommissionPercent: '', //中介佣金比例,即佣金占月租金比例
        flagList: [{
          name: '',
          code: 'Y'
        }],
        breakPriceFlag: '',
        contractAmount: '',
        isYajin: false,
        // 折扣月租金
        haveYZJ: false,
        rentDiscountRate: '',
        rentDiscount4Rate: '',
        rentDiscountPriceDay: '',
        rentDiscount4PriceDay: '',
        rentDiscountPriceMonth: '',
        rentDiscount4PriceMonth: '',
        //有效月租金
        effective_rent_month:'',
        //有效日租金
        effective_rent_day:'',
				//无需更改的账单信息
				not_update_info_list: [],
        isYCXExpenseFlag: false,
        ycxExpenseTimeIndex: 0,
        selectedYcxEndDate: '',
      }
    },
    filters: {
      toFixed2: function (n) {
        return Number(n).toFixed(2)
      }
    },
    watch: {
      payDate() {
        if (this.turnoverCheckBox == 'Y') {
          this.paymentCycle = this.rentBill.pay
        }
      }
    },
    computed: {
      payDate() {
        return this.rentBill.pay
      },
      isSHowYJFlag() {
        if (this.rentBill.oPrice && this.rentBill.dRent && this.rentBill.mRent && this.rentBill.pay) {
          return true
        }
        return false
      },
      ptotal: function () {
        var result = 0;
        this.costItem.map(function (item) {
          if (item.expense_type == 'P') {
            result++
          }
        })
        return result
      },
      ototal: function () {
        var result = 0;
        this.costItem.map(function (item) {
          if (item.expense_type == 'O') {
            result++
          }
        })
        return result
      },
      dototal: function () {
        var result = 0;
        this.costItem.map(function (item) {
          if (item.expense_type == 'D') {
            result++
          }
        })
        return result
      },
      ttotal: function () {
        var result = 0;
        this.costItem.map(function (item) {
          if (item.expense_type == 'T') {
            result++
          }
        })
        return result
      },
      wpNum: function () {
        var num = 0;
        if (this.getCtPrevData.projectInfo.wpdata) {
          var d = this.getCtPrevData.projectInfo.wpdata;
          var arr = []
          for (var i = 0; i < d.length; i++) {
            for (var j = 0; j < d[i].stop.length; j++) {
              arr.push(d[i].stop[j])
            }
          }
          for (var k = 0; k < arr.length; k++) {
            num++
          }
        }
        return num;
      },
      stNum: function () {
        var num = 0;
        if (this.getCtPrevData.projectInfo.stdata) {
          var d = this.getCtPrevData.projectInfo.stdata;
          var arr = []
          for (var i = 0; i < d.length; i++) {
            for (var j = 0; j < d[i].stop.length; j++) {
              arr.push(d[i].stop[j])
            }
          }
          for (var k = 0; k < arr.length; k++) {
            num++
          }
        }
        return num;
      },
      utAge: function () {
        var num = 0;
        if (this.getCtPrevData.projectInfo.units) {
          var d = this.getCtPrevData.projectInfo.units;
          for (var i = 0; i < d.length; i++) {
            num += Number(d[i].unit_acreage)
          }
        }
        return num;
      },
      yaTotal() {
        let num = Number(this.rentBill.menoy) || 0
        this.costItem.map(item => {
          if (item.expense_type == 'D') {
            num = num + Number(item.amount)
          }
        })
        return num.toFixed(2)
      },
    },
    methods: {
      openYCXExpenseFlag(i) {
        this.isYCXExpenseFlag = true
        this.ycxExpenseTimeIndex = i
      },
      // 折扣月租金
      goToCalculation() {
        if (!this.isRequiredDate()) return
        this.atAges = this.utAge;
        this.wpNums = this.wpNum;
        window.sessionStorage.setItem('CREATED_CONTRACT_SECOND_STEP', JSON.stringify(this.$data))
        hlUrlUtil.goTo('discountCalculation', {
          ddtab: true,
        }, true)
      },
      // 计算押金的一次性费项的总额
      yaTotalFun(val1, val2, index) {
        this.costItem[index].amount = (this.utAge * val1 * val2).toFixed(2)
      },
      // 获取意向金抵扣
      isYXDKflag() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            'module_code': 'YIXA',
            'config_name': 'YX_INTENT_CASH_DEDUCTION_TYPE_CONFIG'
          },
          success: res => {
            console.log(res)
            if (res[0].dictValue == 'DEDUCTIONRENTDEPOSIT') {
              this.isYajin = true
            }
          }
        })
      },
      // 获取破底价配置
      getBreakPrice() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            'module_code': 'CIWU',
            'config_name': 'CW_BREAK_PRICE_REMINDER_TYPE_CONFIG'
          },
          success: res => {
            // CONTRASTPRICE 与预签约单价比较
            // CONTRASTRENT  与有效租金比较
            this.breakPriceFlag = res[0].dictValue == 'CONTRASTRENT' ? 'CR' : 'CP'
          }
        })
      },


      // 计算中介佣金
      calIntermediary(type) {
        if (!this.mRent) {
          hl.toast('请先输入月租金')
          this.intermediaryCommissionPercent = ''
          this.intermediaryCommission = ''
          this.intermediaryCommission4 = ''
          return
        }
        if (type == 'v') {
          if (!this.intermediaryCommission) return
          this.intermediaryCommission4 = Number(this.intermediaryCommission).toFixed(4)
          this.intermediaryCommission = Number(this.intermediaryCommission).toFixed(2)
          this.intermediaryCommissionPercent = ((Number(this.intermediaryCommission4) / Number(this.rentBill.mRent)) * 100).toFixed(0)
        }
        if (type == 'p') {
          this.intermediaryCommission4 = Number(this.rentBill.mRent * this.intermediaryCommissionPercent / 100).toFixed(4)
          this.intermediaryCommission = Number(this.rentBill.mRent * this.intermediaryCommissionPercent / 100).toFixed(2)
        }
        if (Number(this.intermediaryCommission4) == 0) {
          this.intermediaryCommission4 = ''
          this.intermediaryCommission = ''
        }
      },
      // 获取是否在合同中体现中介佣金
      getCommission() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            'module_code': 'ZHSH',
            'config_name': 'ZS_CHANNEL_INTERMEDIARY'
          },
          success: res => {
            this.commissionStatus = res[0].status
          }
        })
      },




      // 周期性费项计算日月租金
      calculateDM(val, index, price) {
        console.log(val)
        console.log(index)
        console.log(price)
        if (!val.length || !price) return
        if (this.wpNum) {
          this.acreage = this.wpNum
        } else {
          this.acreage = this.utAge
        }
        this.expenditureUnit.map(item => {
          if (item.dictCode == val + '' && item.systemDefaultType) {
            this.costItem[index].unitsVal = item.dictName
            if (item.systemDefaultType == 'D') {
              let temPrice = Number(price).toFixed(4)
              this.costItem[index].priceDayCopy = (Number(temPrice * this.acreage * 100) / 100).toFixed(4);
              this.costItem[index].priceDay = Number(JSON.parse(JSON.stringify(this.costItem[index].priceDayCopy))).toFixed(2);
              this.costItem[index].priceMonthCopy = (Number(temPrice * this.acreage * this.rentProperty / 12 * 100) / 100).toFixed(4);
              this.costItem[index].priceMonth = Number(JSON.parse(JSON.stringify(this.costItem[index].priceMonthCopy))).toFixed(2);
            }
            if (item.systemDefaultType == 'M') {
              let temPrice = Number(price).toFixed(4)
              this.costItem[index].priceDayCopy = Number(temPrice * this.acreage * 12 / this.rentProperty).toFixed(4);
              this.costItem[index].priceDay = Number(JSON.parse(JSON.stringify(this.costItem[index].priceDayCopy))).toFixed(2);
              this.costItem[index].priceMonthCopy = Number(temPrice * this.acreage).toFixed(4);
              this.costItem[index].priceMonth = Number(JSON.parse(JSON.stringify(this.costItem[index].priceMonthCopy))).toFixed(2);
            }
          }
        })
        console.log(val)
        console.log(index)
      },
      // 获取费项计量单位
      get_CM_EXPENDITURE_UNIT() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CMMN',
            config_name: 'CM_EXPENDITURE_UNIT',
          },
          success: res => {
            let arr = []
            res.map(item => {
              if (item.status == 'Y') {
                arr.push(item)
              }
            })
            arr.map(item => {
              if (item.dictProperty) {
                item.systemDefaultFlag = JSON.parse(item.dictProperty).systemDefaultFlag
                item.systemDefaultType = JSON.parse(item.dictProperty).pExpenseCalDimension //systemDefaultType后台突然改名称 以前是systemDefaultType，懂？
              }
              item.name = item.dictName
              item.code = item.dictCode
            })
            console.log(arr)
            this.expenditureUnit = arr
          }
        })
      },
      // 快捷选择
      selectTimeListActive(val, el, item) {
        this.timeList.active = [item.code]
        this.setendDate()
      },
      setendDate() {
        if (this.timeList.active.join('') < 1) {
          this.endDate = hlDateUtil.monthInterval(this.beginDate, this.timeList.active * 10)
        } else {
          this.endDate = hlDateUtil.dateInterval(this.beginDate, this.timeList.active * 1)
        }
      },
      //收款日
      selectBFActive(val, el, item) {
        this.billDate.BFCode = [item.code]
      },
      selectDayActive(val, el, item) {
        this.billDate.dayCode = [item.code]
      },
      //////////////////////////////固定租金///////////////////////
      // 新增与删除
      setGDZJ() {
        this.isGDZJflag = !this.isGDZJflag
        this.rentBill.oPrice = ''
        this.rentBill.dRent = ''
        this.rentBill.mRent = ''
        this.rentBill.pay = ''
        this.rentBill.rentPercent = ''
        this.oPrice = ''
        this.dRent = ''
        this.mRent = ''
        this.turnoverCheckBox = 'N'
        // 折扣月租金
        this.rentDiscountRate = ''
        this.rentDiscount4Rate = ''
        this.rentDiscountPriceDay = ''
        this.rentDiscount4PriceDay = ''
        this.rentDiscountPriceMonth = ''
        this.rentDiscount4PriceMonth = ''

      },
      //租金下拉选择
      setUnitGr: function () {
        this.rentBill.oPrice = '';
        this.rentBill.dRent = '';
        this.rentBill.mRent = '';
        this.rentBill.bet = '';
        this.rentBill.menoy = '';
        this.rentBill.pay = '';
        this.oPrice = '';
        this.dRent = '';
        this.mRent = '';
        this.menoy = '';
        this.rentLadder = [];
        this.copyRentLadderArr = [];
        this.freePeriod = [];
        this.dayRentPriceAlert = '';
        this.monthRentPriceAlert = '';
      },
      //验证工位单元
      yzunitwp: function () {
        if (this.getCtPrevData.contactType.active == 'ER') {
          this.setUnit.active = 'one'
        } else {
          this.setUnit.active = 'two'
        }
      },
      //计算租金押金   1  租金单价  2  日租金  3  月租金
      calculateRent: function (n, i) {
        this.hidebillPlan('Y', this.rentBill.bet, 'bet')
        if (!n) return
        if (this.wpNum) {
          this.acreage = this.wpNum
        } else {
          this.acreage = this.utAge
        }
        // 如果租金单价、日租金、月租金有值的情况下则不做联动计算
        if (this.oPrice && this.dRent && this.mRent) {
          if (this.breakPriceFlag == 'CP') {
            this.isSatisfyMinPrice()
          }
          if (i == 1) {
            this.rentBill.oPrice = Number(JSON.parse(JSON.stringify(this.oPrice))).toFixed(4)
          }
          if (i == 2) {
            this.rentBill.dRent = Number(JSON.parse(JSON.stringify(this.dRent))).toFixed(4)
          }
          if (i == 3) {
            this.rentBill.mRent = Number(JSON.parse(JSON.stringify(this.mRent))).toFixed(4)
            if (this.intermediaryCommissionPercent) {
              this.calIntermediary('p')
            }
          }
          return false;
        }
        // 当租金单价 、 日租金 、 月租金没有值时，输入租金单价做联动处理
        // 按照月算
        if (this.setUnit.nIndex.join('') == 1) {
          if (i == 1) {
            this.oPrice = Number(n).toFixed(2)
            this.rentBill.oPrice = Number(n).toFixed(4)
            this.rentBill.dRent = Number(this.rentBill.oPrice * this.acreage * 12 / this.rentProperty).toFixed(4);
            this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
            this.rentBill.mRent = Number(this.rentBill.oPrice * this.acreage).toFixed(4);
            this.mRent = Number(JSON.parse(JSON.stringify(this.rentBill.mRent))).toFixed(2);
          }
          if (i == 2) {
            this.rentBill.dRent = Number(n).toFixed(4)
            this.dRent = Number(n).toFixed(2)
            if (this.acreage == 0) {
              this.rentBill.oPrice = 0;
              this.oPrice = 0;
            } else {
              this.rentBill.oPrice = Number(this.rentBill.dRent * this.rentProperty / 12 / this.acreage).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            this.rentBill.mRent = Number(this.rentBill.dRent * this.rentProperty / 12).toFixed(4);
            this.mRent = Number(JSON.stringify(this.rentBill.mRent)).toFixed(2);
          }
          if (i == 3) {
            this.rentBill.mRent = Number(n).toFixed(4)
            this.mRent = Number(n).toFixed(2)
            if (this.acreage == 0) {
              this.rentBill.oPrice = 0;
              this.oPrice = 0;
            } else {
              this.rentBill.oPrice = Number(this.rentBill.mRent / this.acreage).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            this.rentBill.dRent = Number(this.rentBill.mRent * 12 / this.rentProperty).toFixed(4);
            this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
          }
        }

        // 按照日算
        if (this.setUnit.nIndex.join('') == 0) {
          if (i == 1) {
            this.oPrice = Number(n).toFixed(2)
            this.rentBill.oPrice = Number(n).toFixed(4)
            this.rentBill.dRent = (Number(this.rentBill.oPrice * this.acreage * 100) / 100).toFixed(4);
            this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
            this.rentBill.mRent = (Number(this.rentBill.oPrice * this.acreage * this.rentProperty / 12 * 100) / 100).toFixed(4);
            this.mRent = Number(JSON.parse(JSON.stringify(this.rentBill.mRent))).toFixed(2);
          }
          if (i == 2) {
            this.rentBill.dRent = Number(JSON.parse(JSON.stringify(n))).toFixed(4)
            this.dRent = Number(n).toFixed(2)
            if (this.acreage == 0) {
              this.rentBill.oPrice = 0;
              this.oPrice = 0;
            } else {
              this.rentBill.oPrice = (Number(this.rentBill.dRent / this.acreage * 100) / 100).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            this.rentBill.mRent = (Number(this.rentBill.dRent * this.rentProperty / 12 * 100) / 100).toFixed(4);
            this.mRent = Number(JSON.parse(JSON.stringify(this.rentBill.mRent))).toFixed(2);
          }
          if (i == 3) {
            this.rentBill.mRent = Number(JSON.parse(JSON.stringify(n))).toFixed(4)
            this.mRent = Number(n).toFixed(2)
            if (this.acreage == 0) {
              this.rentBill.oPrice = 0;
              this.oPrice = 0;
            } else {
              this.rentBill.oPrice = Number(this.rentBill.mRent * 12 / this.rentProperty / this.acreage).toFixed(4);
              this.oPrice = Number(JSON.parse(JSON.stringify(this.rentBill.oPrice))).toFixed(2);
            }
            this.rentBill.dRent = Number(this.rentBill.mRent * 12 / this.rentProperty).toFixed(4);
            this.dRent = Number(JSON.parse(JSON.stringify(this.rentBill.dRent))).toFixed(2);
          }
        }
        if (this.breakPriceFlag == 'CP') {
          this.isSatisfyMinPrice()
        }
      },
      // 判断价格是否符合底价策略
      isSatisfyMinPrice: function () {
        var self = this;
        var prevData = self.getCtPrevData
        // 所选合同类型  WP 工位   UN 单元
        var type = prevData.contactType.active === 'WR' ? 'WP' : 'UN'
        // 所选单元或者工位id  如果只选车位 则不掉用底价策略
        var getUnitIds = function () {
          var res = [];
          prevData.unitData.map(function (_item) {
            res.push(_item.unit_id)
          })
          return res.join()
        }
        var getWpIds = function () {
          var res = [];
          prevData.wpData.map(function (item) {
            item.stop.map(function (_item) {
              res.push(_item.positionId)
            })
          })
          return res.join()
        }
        var ids = null;
        if (type === 'WP') {
          ids = getWpIds()
        }
        if (type === 'UN') {
          ids = getUnitIds()
        }
        // 日租金、月租金计算
        var acreage = self.wpNum ? self.wpNum : this.utAge;
        var rentPriceDay = self.rentBill.dRent / acreage;
        var rentPriceMonth = Number(self.rentBill.mRent / acreage).toFixed(2)

        if (prevData.unitData.length !== 0 || prevData.wpData.length !== 0) {
          hlhttp.put({
            url: 'check_base_price_policy',
            data: {
              rent_price_day: Number(rentPriceDay).toFixed(2),
              rent_price_month: Number(rentPriceMonth).toFixed(2),
              type: type,
              ids: ids,
              policy_type: this.breakPriceFlag || '#',
              contract_amount: this.contractAmount.toFixed(2) || '#',
              contract_begin_date: this.beginDate,
              contract_end_date: this.endDate || "#",
            },
            success: function (data) {
              // 与有效租金比较（CR）预签约单价比较（CP）
              if (data.result === 'N') {
                if (data.rentPriceType === 'D') {
                  if (type === 'WP') {
                    self.dayRentPriceAlert = '日租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentDay + '元/个/天,') : '') + '低于工位底价' + data.memo + '元/个/天'
                    self.monthRentPriceAlert = ''
                  }
                  if (type === 'UN') {
                    self.dayRentPriceAlert = '日租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentDay + '元/m²/天,') : '') + '低于单元底价' + data.memo + '元/m²/天'
                    self.monthRentPriceAlert = ''
                  }
                }
                if (data.rentPriceType === 'M') {
                  if (type === 'WP') {
                    self.monthRentPriceAlert = '月租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentMonth + '元/个/月,') : '') + '低于工位底价' + (Number(data.memo)).toFixed(2) + '元/个/月'
                    self.dayRentPriceAlert = ''
                  }
                  if (type === 'UN') {
                    self.monthRentPriceAlert = '月租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentMonth + '元/m²/月,') : '') + '低于单元底价' + (Number(data.memo)).toFixed(2) + '元/m²/月'
                    self.dayRentPriceAlert = ''
                  }
                }
                if (data.rentPriceType === 'A') {
                  if (type === 'WP') {
                    self.dayRentPriceAlert = '日租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentDay + '元/个/天,') : '') + '低于工位底价' + data.memo.split(',')[0] + '元/个/天'
                    self.monthRentPriceAlert = '月租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentMonth + '元/个/月,') : '') + '低于工位底价' + Number(data.memo.split(',')[1] || '0').toFixed(2) + '元/个/月'
                  }
                  if (type === 'UN') {
                    self.dayRentPriceAlert = '日租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentDay + '元/m²/天,') : '') + '低于单元底价' + data.memo.split(',')[0] + '元/m²/天'
                    self.monthRentPriceAlert = '月租金' + (self.breakPriceFlag == 'CR' ? ('有效租金' + data.effectiveRentMonth + '元/m²/月,') : '') + '低于单元底价' + Number(data.memo.split(',')[1] || '0').toFixed(2) + '元/m²/月'
                  }
                }
                if (self.breakPriceFlag == 'CR') {
                  hllayer.confirm3(self.dayRentPriceAlert + '<br/>' + self.monthRentPriceAlert, () => {

                  })
                }
              }
              if (data.result === 'Y') {
                self.dayRentPriceAlert = ''
                self.monthRentPriceAlert = ''
              }
              self.effective_rent_day = data.effectiveRentDay ? data.effectiveRentDay : '#'
              self.effective_rent_month = data.effectiveRentMonth ? data.effectiveRentMonth : '#'
            }
          })
        }
      },
      // 获取选中租金计算周期
      getSelfRent() {
        var that = this
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_RENT_CALCULATE_PERIOD_TYPE_CONFIG',
          },
          success: function (res) {
            that.rentProperty = [res[0].dictProperty]
          }
        })
      },
      //////////////////////////////押金//////////////////
      // 新增与删除
      setYJ() {
        this.isYJflag = !this.isYJflag
        this.rentBill.bet = ''
        this.rentBill.menoy = ''
        this.rentBill.proportion = ''
        this.menoy = ''
      },
      hidebillPlan(ishide, val, type) {
        if (!val) {
          return
        }
        if (ishide) {

        }
        if (type == 'bet') {
          if (this.SQdate && this.dRent && this.rentBill.pay && this.setRent.active[0] == 'D') {
            hlhttp.get({
              url: 'contract/deposit_calc/by_day',
              data: {
                pay_date: this.SQdate,
                price_day: this.rentBill.dRent,
                period: this.rentBill.bet,
                rent_way: this.setRent.active + ''
              },
              success: (data) => {
                this.rentBill.menoy = data.amount
                this.menoy = JSON.parse(JSON.stringify(Number(data.amount).toFixed(2)))
              }
            })
            return
          }
          this.rentBill.menoy = Number(this.rentBill.bet * this.rentBill.mRent).toFixed(4)
          this.menoy = Number(this.rentBill.bet * this.rentBill.mRent).toFixed(2)
        }
        if (type == 'menoy') {
          if (this.menoy === '') {
            this.rentBill.menoy = ''
            return
          }
          this.rentBill.menoy = Number(JSON.parse(JSON.stringify(this.menoy))).toFixed(4)
        }
      },
      ///////////////////////////////阶梯租金/////////////
      addJTZJ() {
        if (!this.isRequiredDate()) {
          return
        }
        let flag = false;

        this.rentLadder.map(item => {
          if (!item.lv || !item.dj || !item.rz || !item.yz) {
            flag = true;
          }
          // 折扣月租金
          if (this.haveYZJ) {
            if (!item.dis || !item.disD || !item.disM) {
              flag = true;
            }
          }
        })

        if (flag) {
          hl.toast('请完善上一个阶梯租金信息')
          return
        }
        this.rentLadder.push({
          time: '',
          lv: '',
          dj: '',
          rz: '',
          yz: '',
          // 折扣月租金
          dis: '',
          disD: '',
          disM: '',
        })
        this.copyRentLadderArr.push({
          time: '',
          lv: '',
          dj: '',
          rz: '',
          yz: '',
          // 折扣月租金
          dis: '',
          disD: '',
          disM: '',
        })
      },
      // 删除阶梯租金
      delJTZJ(index) {
        this.rentLadder.splice(index, 1)
        this.copyRentLadderArr.splice(index, 1)
        if (this.rentLadder.length == 0) {
          this.ladderRentActive = [this.ladderRentArr[0].dictCode]
        }
      },

      // 获取递增时间
      ladderRentConfig() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_DIFFERENTIAL_PRICING_EFFECTIVE_TYPE'
          },
          success: (data) => {
            data.map(item => {
              item.name = item.dictName
              item.code = item.dictCode
            })
            this.ladderRentArr = data;
            this.ladderRentActive = [data[0].dictCode]
          }
        })
      },

      //计算阶梯租金
      calculateRentLd: function (n, i, s, e) {
        if (!n) return
        if (this.wpNum) {
          this.acreage = this.wpNum
        } else {
          this.acreage = this.utAge
        }
        //副本
        if (this.rentLadder[i].dj && this.rentLadder[i].lv && this.rentLadder[i].rz && this.rentLadder[i].yz) {
          if (s == 1) {
            this.copyRentLadderArr[i].lv = JSON.parse(JSON.stringify(this.rentLadder[i].lv))
          }
          if (s == 2) {
            this.copyRentLadderArr[i].dj = JSON.parse(JSON.stringify(this.rentLadder[i].dj))
          }
          if (s == 3) {
            this.copyRentLadderArr[i].rz = JSON.parse(JSON.stringify(this.rentLadder[i].rz))
          }
          if (s == 4) {
            this.copyRentLadderArr[i].yz = JSON.parse(JSON.stringify(this.rentLadder[i].yz))
          }
          return
        };
        if (s == 1) {
          if (this.rentLadder.length > 1) {
            this.rentLadder[i].dj = (Number(this.rentLadder[i - 1].dj * (n / 100)) +
              Number(this.rentLadder[i - 1].dj)).toFixed(2);
            //副本
            this.copyRentLadderArr[i].dj = (Number(this.rentLadder[i - 1].dj * (n / 100)) +
              Number(this.rentLadder[i - 1].dj)).toFixed(4);
          } else {
            this.rentLadder[i].dj = (Number(this.rentBill.oPrice * (n / 100)) +
              Number(this.rentBill.oPrice)).toFixed(2);
            //副本
            this.copyRentLadderArr[i].dj = (Number(this.rentBill.oPrice * (n / 100)) +
              Number(this.rentBill.oPrice)).toFixed(4);
          }
          if (this.setUnit.nIndex == 0) {
            this.rentLadder[i].rz = Number(this.rentLadder[i].dj * this.acreage).toFixed(2);
            this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(2);
            //副本
            this.copyRentLadderArr[i].rz = Number(this.rentLadder[i].dj * this.acreage).toFixed(4);
            this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(4);
          } else {
            this.rentLadder[i].rz = Number(this.rentLadder[i].dj * this.acreage * 12 / this.rentProperty).toFixed(2);
            this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(2);
            //副本
            this.copyRentLadderArr[i].rz = Number(this.rentLadder[i].dj * this.acreage * 12 / this.rentProperty).toFixed(4);
            this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(4);
          }
          this.rentLadder[i].lv = n;
          //副本
          this.copyRentLadderArr[i].lv = n;
        }
        if (s == 2) {
          if (this.setUnit.nIndex == 0) {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentLadder[i - 1].dj * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * this.acreage).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentLadder[i - 1].dj * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * this.acreage).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentBill.oPrice * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * this.acreage).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentBill.oPrice * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * this.acreage).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(4);
            }
          } else {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentLadder[i - 1].dj * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * this.acreage * 12 / this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentLadder[i - 1].dj * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * this.acreage * 12 / this.rentProperty).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentBill.oPrice * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * this.acreage * 12 / this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentBill.oPrice * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * this.acreage * 12 / this.rentProperty).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(4);
            }
          }
        }
        if (s == 3) {
          if (this.setUnit.nIndex == 0) {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n / this.acreage).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentLadder[i - 1].rz * 100 - 100).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n / this.acreage).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentLadder[i - 1].rz * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n / this.acreage).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentBill.dRent * 100 - 100).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n / this.acreage).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentBill.dRent * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage * this.rentProperty / 12).toFixed(4);
            }
          } else {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n / this.acreage * this.rentProperty / 12).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentLadder[i - 1].rz * 100 - 100).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n / this.acreage * this.rentProperty / 12).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentLadder[i - 1].rz * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n / this.acreage * this.rentProperty / 12).toFixed(2);
              this.rentLadder[i].rz = Number(n).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentBill.dRent * 100 - 100).toFixed(2);
              this.rentLadder[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n / this.acreage * this.rentProperty / 12).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentBill.dRent * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(this.rentLadder[i].dj * this.acreage).toFixed(4);
            }
          }
        }
        if (s == 4) {
          if (this.setUnit.nIndex == 0) {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n * 12 / this.rentProperty / this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentLadder[i - 1].yz * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * 12 / this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n * 12 / this.rentProperty / this.acreage).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentLadder[i - 1].yz * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * 12 / this.rentProperty).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n * 12 / this.rentProperty / this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentBill.mRent * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * 12 / this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n * 12 / this.rentProperty / this.acreage).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentBill.mRent * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * 12 / this.rentProperty).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            }
          } else {
            if (this.rentLadder.length > 1) {
              this.rentLadder[i].dj = Number(n / this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentLadder[i - 1].yz * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * 12 / this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n / this.acreage).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentLadder[i - 1].yz * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * 12 / this.rentProperty).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            } else {
              this.rentLadder[i].dj = Number(n / this.acreage).toFixed(2);
              this.rentLadder[i].lv = Number(n / this.rentBill.mRent * 100 - 100).toFixed(2);
              this.rentLadder[i].rz = Number(n * 12 / this.rentProperty).toFixed(2);
              this.rentLadder[i].yz = Number(n).toFixed(2);
              //副本
              this.copyRentLadderArr[i].dj = Number(n / this.acreage).toFixed(4);
              this.copyRentLadderArr[i].lv = Number(n / this.rentBill.mRent * 100 - 100).toFixed(4);
              this.copyRentLadderArr[i].rz = Number(n * 12 / this.rentProperty).toFixed(4);
              this.copyRentLadderArr[i].yz = Number(n).toFixed(4);
            }
          }
        }
      },
      /////////////////////////////////////////////////// 免租期//////////////
      addMZQ() {
        if (!this.isRequiredDate()) {
          return
        }
        let flag = false
        this.freePeriod.map(item => {
          if (!item.btime || !item.etime) {
            flag = true;
          }
        })
        if (flag) {
          hl.toast('请完善上一个免租期/装修期')
          return
        }
        this.freePeriod.push({
          btime: '',
          etime: '',
          flag: [],
          memo: ''
        })
      },
      /////////////////////////////////////////////////////// 营业额抽成///////////////
      setYYECC() {
        this.isYYECCflag = !this.isYYECCflag
      },
      // 获取抽成类型
      getTurnoverArr() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'HETN',
            config_name: 'HT_COMMISSION_TYPE'
          },
          success: (data) => {
            data.map(item => {
              item.name = item.dictName
              item.code = item.dictCode
            })
            this.turnoverArr = data;
          }
        })
      },
      //与租金取其高
      takeHigh() {
        if (!(this.oPrice && this.dRent && this.mRent && this.rentBill.pay)) {
          hl.toast('请完善固定租金信息')
          this.turnoverCheckBox = 'N';
          return
        }
        this.turnoverCheckBox = this.turnoverCheckBox == 'N' ? 'Y' : 'N';
        if (this.turnoverCheckBox == 'Y') {
          this.paymentCycle = this.rentBill.pay
        }
      },
      // 新增基数列表
      addYYE(i) {
        if (this.tableArr.length > 1) {
          if (!this.tableArr[this.tableArr.length - 2].base_val_up_limit) {
            hl.toast('请填写上一个基数上限')
            return
          }
        }
        this.tableArr.push({
          base_val_down_limit: this.tableArr[this.tableArr.length - 1].base_val_up_limit ? this.tableArr[this.tableArr.length - 1].base_val_up_limit : this.tableArr[this.tableArr.length - 1].base_val_down_limit,
          base_val_up_limit: '',
          commission_percent: '',
          commission_down_limit: '',
          commission_up_limit: '',
          late_fee_percent: '',
          payemnt_period: ''
        })
        if (this.tableArr[0].payemnt_period) {
          this.tableArr.map(item => {
            item.payemnt_period = this.tableArr[0].payemnt_period
          })
        }
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      //抽成下限判断
      isLowerYYE(i) {
        if (!this.tableArr[i].commission_up_limit) return;
        if (Number(this.tableArr[i].commission_up_limit) < Number(this.tableArr[i].commission_down_limit)) {
          this.tableArr[i].commission_down_limit = '';
          hl.toast('抽成上限不得大于抽成下限')
          return
        }
      },
      //抽成上限判断
      isUpYYE(i) {
        if (!this.tableArr[i].commission_up_limit) return;
        if (Number(this.tableArr[i].commission_up_limit) < Number(this.tableArr[i].commission_down_limit)) {
          this.tableArr[i].commission_up_limit = '';
          hl.toast('抽成上限不得小于抽成下限')
          return
        }
      },
      //删除某个基数
      removeYYE(i) {
        this.tableArr.splice(i, 1)
        this.tableArr[0].base_val_down_limit = '0';
        if (this.tableArr.length > 1) {
          for (let i = 0; i < this.tableArr.length; i++) {
            if (i + 1 < this.tableArr.length) {
              this.tableArr[i + 1].base_val_down_limit = ''
              this.tableArr[i + 1].base_val_down_limit = this.tableArr[i].base_val_up_limit
            }
          }
        }
        $('#pay-plan, .ct-ceat-btn').hide()
      },
      //修改基数上限
      blurYYE(i) {
        $('#pay-plan, .ct-ceat-btn').hide()
        if (Number(this.tableArr[i].base_val_down_limit) >= Number(this.tableArr[i].base_val_up_limit)) {
          hl.toast('基数上限必须大于基数下限')
          this.tableArr[i].base_val_up_limit = '';
          return
        }
        if (this.tableArr.length - 1 >= i + 1) {
          this.tableArr[i + 1].base_val_down_limit = this.tableArr[i].base_val_up_limit
        }
        this.tableArr[this.tableArr.length - 1].base_val_down_limit = this.tableArr[this.tableArr.length - 2].base_val_up_limit
      },
      handleFKZQblur(val) {
        this.costItem.forEach(el => {
          if(el.expense_type == 'P' && el.customPeriod.length == 0) el.expense_period = val
        })
      },
      //新增费项
      addCostItem: function (type) {
        if( this.rentBill.pay == 0 && type == 'P'){
          hl.toast('请填写固定租金付款周期')
          return false
        }

        this.costItem.push({
          unitsVal: '',
          unitsCode: [],
          expense_code: [],
          expense_name: '',
          amount: '',
          price: '',
          priceDay: '',
          priceMonth: '',
          priceDayCopy: '',
          priceMonthCopy: '',
          expense_period: this.rentBill.pay,
          expense_type: type,
          late_fee: '',
          customPeriod: [],
          tax_percent: ''
        })
      },
      //点击获取新增费项类型
      getcostY: function (i, type) {
        this.cTIndex = i;
        // this.cTType = type;
        // event.stopPropagation()
      },
      getCtData: function () {
        var that = this;
        hlhttp.get({
          url: 'valid_expenditures',
          success: function (res) {
            res.map(item => {
              item.code = item.id
              if (item.type == 'P') {
                that.cTData_P.push(item)
              }
              if (item.type == 'O') {
                that.cTData_O.push(item)
              }
              if (item.type == 'R') {
                that.haveGDflag = true
              }
              if (item.type == 'D') {
                that.haveYJflag = true
              }
              if (item.type == 'CM') {
                that.haveYYECCflag = true
              }
            })
          }
        })
      },
      getCTtype(val, type) {
        console.log(val)
        let flag = true
        console.log(this.cTIndex)
        this.costItem.some(item => {
          if (item.expense_name == val[0].name) {
            hl.toast('已有该费项')
            this.costItem[this.cTIndex].unitsVal = ''
            this.costItem[this.cTIndex].unitsCode = []
            this.costItem[this.cTIndex].expense_code = []
            this.costItem[this.cTIndex].expense_name = ''
            this.costItem[this.cTIndex].amount = ''
            this.costItem[this.cTIndex].price = ''
            this.costItem[this.cTIndex].priceDay = ''
            this.costItem[this.cTIndex].priceMonth = ''
            this.costItem[this.cTIndex].priceDayCopy = ''
            this.costItem[this.cTIndex].priceMonthCopy = ''
            this.costItem[this.cTIndex].expense_period = ''
            this.costItem[this.cTIndex].expense_type = type ? type : val[0].type
            this.costItem[this.cTIndex].late_fee = ''
            this.costItem[this.cTIndex].tax_percent = ''
            this.costItem[this.cTIndex].customPeriod = []
            // this.costItem.splice(this.cTIndex, 1)
            flag = false
          }
        })
        if (!flag) {
          return
        }
        this.costItem[this.cTIndex].unitsVal = val[0].unitsVal || ''
        this.costItem[this.cTIndex].unitsCode = val[0].unitsCode ? [val[0].unitsCode] : []
        this.costItem[this.cTIndex].late_fee = val[0].lateFee || ''
        this.costItem[this.cTIndex].expense_name = val[0].name || ''
      },
      // 计费时间
      putEindex: function (i) {
        if (!this.isRequiredDate()) {
          return
        }
        this.isZQXFXtimeFlag = true
        this.cTIndex = i;
        this.setZXQFXtimeList = JSON.parse(JSON.stringify(this.costItem[i].customPeriod))
      },
      // 添加一行
      addDate() {
        let flag = true
        this.setZXQFXtimeList.some(item => {
          if (!item.begin_date || !item.end_date) {
            hl.toast('请先完成再添加')
            flag = false
          }
        })
        if (flag) {
          this.setZXQFXtimeList.push({
            begin_date: '',
            end_date: ''
          })
        }
      },
      //自动补全
      completion() {
        let flag = true
        if (this.setZXQFXtimeList.length) {
          this.setZXQFXtimeList.some(item => {
            if (!item.begin_date || !item.end_date) {
              flag = false
            }
          })
        }
        if (!flag) {
          return
        }
        let ld = {}
        let cp = {}
        ld.begin_date = this.setZXQFXtimeList[this.setZXQFXtimeList.length - 1].begin_date
        ld.end_date = this.setZXQFXtimeList[this.setZXQFXtimeList.length - 1].end_date
        cp.begin_date = this.beginDate
        cp.end_date = this.endDate
        var that = this
        hlhttp.get({
          url: 'fill_up_custom_period',
          data: {
            last_period: JSON.stringify(ld),
            contract_period: JSON.stringify(cp)
          },
          success: function (res) {
            res.customPeriod.map(function (item, index) {
              that.setZXQFXtimeList.push({
                begin_date: hlDateUtil.formatUTCDate(item.beginDate, 'yyyy-MM-dd'),
                end_date: hlDateUtil.formatUTCDate(item.endDate, 'yyyy-MM-dd')
              })
            })
          }
        })
      },
      // 删除一行(时间段)
      delZQXFXtime(index) {
        this.setZXQFXtimeList.splice(index, 1)
      },
      // 检测时间段是否填写正确
      checkZQXFXtime(valA, valB, index, type) {
        // return
        var timeA = hlDateUtil.shellDate(valA) //开始时间
        var timeB = hlDateUtil.shellDate(valB) //结束时间
        var timeC = hlDateUtil.shellDate(this.beginDate) //租赁开始时间
        var timeD = hlDateUtil.shellDate(this.endDate) //租赁结束时间
        var timeE = this.setZXQFXtimeList[index - 1] ? hlDateUtil.shellDate(this.setZXQFXtimeList[index - 1].end_date) : '' //上一个结束时间
        var timeF = this.setZXQFXtimeList[index + 1] ? hlDateUtil.shellDate(this.setZXQFXtimeList[index + 1].begin_date) : '' //下一个开始时间
        if (type == 'B') {
          // if (timeA < timeC) {
          //   hl.toast('开始时间不可小于租赁时间')
          //   setTimeout(() => {
          //     this.setZXQFXtimeList[index].begin_date = ''
          //   }, 10);
          //   return
          // }
          // if (timeA > timeD) {
          //   hl.toast('开始时间不可大于租赁时间')
          //   setTimeout(() => {
          //     this.setZXQFXtimeList[index].begin_date = ''
          //   }, 10);
          //   return
          // }
          if (timeB) {
            if (timeA > timeB) {
              hl.toast('开始时间不可大于结束时间')
              setTimeout(() => {
                this.setZXQFXtimeList[index].begin_date = ''
              }, 10);
              return
            }
          }
          if (timeE) {
            if (timeA < timeE) {
              hl.toast('开始时间不能小于上一个结束时间')
              setTimeout(() => {
                this.setZXQFXtimeList[index].begin_date = ''
              }, 10);
              return
            }
          }
        }
        if (type == 'A') {
          // if (timeB < timeC) {
          //   hl.toast('开始时间不可小于租赁时间')
          //   setTimeout(() => {
          //     this.setZXQFXtimeList[index].end_date = ''
          //   }, 10);
          //   return
          // }
          // if (timeB > timeD) {
          //   hl.toast('开始时间不可大于租赁时间')
          //   setTimeout(() => {
          //     this.setZXQFXtimeList[index].end_date = ''
          //   }, 10);
          //   return
          // }
          if (timeA) {
            if (timeA > timeB) {
              hl.toast('结束时间不可小于开始时间')
              setTimeout(() => {
                this.setZXQFXtimeList[index].end_date = ''
              }, 10);
              return
            }
          }
          if (timeF) {
            if (timeB > timeF) {
              hl.toast('结束时间不可小于上一个开始时间')
              setTimeout(() => {
                this.setZXQFXtimeList[index].end_date = ''
              }, 10);
              return
            }
          }
        }
      },

      /////////////////公共部分//////////////
      linkage(val, i, dm) {
        if (dm == 'd') {
          this.costItem[i].priceDayCopy = JSON.parse(JSON.stringify(this.costItem[i].priceDay))
        }
        if (dm == 'm') {
          this.costItem[i].priceMonthCopy = JSON.parse(JSON.stringify(this.costItem[i].priceMonth))
        }

        if (this.costItem[i].priceDay && !this.costItem[i].priceMonth) {
          this.costItem[i].priceMonth = Number(this.costItem[i].priceDay * this.rentProperty / 12).toFixed(2);
          this.costItem[i].priceMonthCopy = Number(this.costItem[i].priceDay * this.rentProperty / 12).toFixed(4);
        }
        if (!this.costItem[i].priceDay && this.costItem[i].priceMonth) {
          this.costItem[i].priceDay = Number(this.costItem[i].priceMonth * 12 / this.rentProperty).toFixed(2);
          this.costItem[i].priceDayCopy = Number(this.costItem[i].priceMonth * 12 / this.rentProperty).toFixed(4);
        }

        if (this.costItem[i].price < 0) {
          this.costItem[i].price = null;
        }
        if (this.costItem[i].amount < 0) {
          this.costItem[i].amount = null;
        }
        if (this.costItem[i].priceDay < 0) {
          this.costItem[i].priceDay = null;
          this.costItem[i].priceDayCopy = null;
        }
        if (this.costItem[i].priceMonth < 0) {
          this.costItem[i].priceMonth = null;
          this.costItem[i].priceMonthCopy = null;
        }
        if (this.costItem[i].expense_period < 0) {
          this.costItem[i].expense_period = null;
        }
      },
      // 上一步
      prevData() {
        this.atAges = this.utAge;
        this.wpNums = this.wpNum;
        window.sessionStorage.setItem('CREATED_CONTRACT_SECOND_STEP', JSON.stringify(this.$data))
        if (this.contractId && this.reletFlag) {
          hlUrlUtil.goTo('contractNew1', {
            ddtab: true,
            relet: true,
            id: this.contractId
          })
          return
        }
        if (this.contractId) {
          hlUrlUtil.goTo('contractNew1', {
            id: this.contractId,
            ddtab: true
          })
        } else {
          hlUrlUtil.goTo('contractNew1', {
            ddtab: true
          })
        }

      },
      // 生成付款计划
      createBillPlan(n) {
        if (this.haveYZJ) {
          if (!(this.rentDiscountPriceDay && this.rentDiscountRate && this.rentDiscountPriceMonth)) {
            hl.toast('请完善折扣金额')
            return
          }
        }
        planDataList = []

        if (!this.isRequiredDate()) {
          return
        }
        if (this.haveGDflag && this.isGDZJflag) {
          if (!this.isRequiredGDZJ()) {
            return
          }
        }
        if (this.haveYJflag && this.isYJflag) {
          if (!this.isRequiredYJ()) {
            return
          }
        }
        if (this.haveGDflag && this.isGDZJflag) {
          if (!this.isRequiredJTZJ()) {
            return
          }
        }
        if (this.haveYYECCflag && this.isYYECCflag) {
          if (!this.isRequiredYYECC()) {
            return
          }
        }
        if (this.freePeriod.length) {
          if (!this.isRequiredMZQ()) {
            return
          }
        }
        if (!this.isCompleteFX()) {
          return
        }
        if (n == 2) {
          let that = this
          hlhttp.get({
            url: 'contracts/bill_plans',
            data: {
              contract_id: this.contractId
            },
            success: function (res) {
              that.payData = res
              that.isPayBillFlag = true
              setTimeout(() => {
                let arr = that.$refs.payPlan.subtotalArr.R || []
                arr.map(item => {
                  if (item.name == "固定租金") {
                    that.contractAmount = item.expense
                  }
                })
                if (that.breakPriceFlag == 'CR') {
                  that.isSatisfyMinPrice()
                }
              }, 500)
            }
          })
          return
        }
        let data = {}

        // let mdate = [] //免租期
        // this.freePeriod.map(item => {
        //   mdate.push(item.btime + '~' + item.etime)
        // })
        let free_dates = []
        this.freePeriod.map(item => {
          free_dates.push({
            free_begin_date: item.btime,
            free_end_date: item.etime,
            bill_hidden_flag: item.flag.length ? 'Y' : 'N',
            free_memo: item.memo,
          })
        })



        let rDate = [] //递增时间
        let rRate = [] //租金递增率
        let price = [] //单价
        let rDay = [] //日递增租金
        let rMonth = [] //月递增租金
        rDay.push(this.rentBill.dRent)
        rMonth.push(this.rentBill.mRent)
        rDate.push(this.beginDate)
        this.copyRentLadderArr.map(item => {
          rDay.push(item.rz)
          rMonth.push(item.yz)
          rRate.push(item.lv)
          price.push(item.dj)
        })

        this.rentLadder.map(item => {
          rDate.push(item.time)
        })
        data.contract = {
          "rent_way": this.setRent.active + '', //租金计算方式，M按月计算、D按天计算
          "period": this.rentBill.pay + '' || '#', //付款周期
          "free_dates": free_dates.length ? JSON.stringify(free_dates) : '#',
          "rent_late_fee_percent": this.rentBill.rentPercent ? (this.rentBill.rentPercent / 100 + '') : '0', //租金滞纳金比例
          "rent_increse_days": rDay.length ? (rDay + '') : '', //日递增租金
          "rent_increse_months": rMonth.length ? (rMonth + '') : '', //月递增租金
          "rent_increse_dates": rDate.length ? (rDate + '') : '', //租金递增日期
          "begin_date": this.beginDate, //合同开始日期
          "end_date": this.endDate, //合同结束日期
          "first_payment_date": this.SQdate, //首期付款日
          "bill_date_BOA": this.billDate.BFCode + '', //账单提醒日 B 账期开始前 A 账期开始后
          "bill_date_fix_type": this.billDate.dayCode + '', //账单提醒日 类型 RQ 固定日期 TS 天数
          "bill_date_fix_num": this.billDate.naturalDay + '', //账单提醒日 指定天数/指定日期
          "rent_increase_way": this.ladderRentActive + '' //租金递增计算方式 C当日计算 N下账期计算
        }
        // 折扣月租金
        if (this.haveYZJ) {
          let arr2 = [this.rentDiscount4PriceDay] //阶梯租金的日租金
          let arr3 = [this.rentDiscount4PriceMonth] //阶梯租金的月租金
          this.copyRentLadderArr.map(item => {
            arr2.push(item.disD)
            arr3.push(item.disM)
          })
          data.contract.rent_increse_discount_day = arr2 + ''
          data.contract.rent_increse_discount_month = arr3 + ''
        }

        let expenses = []
        this.costItem.map(item => {
          if (item.expense_type == 'P' || item.expense_type == 'O' || item.expense_type == 'T') {
            let obj = {
              "name": item.expense_name + '',
              "period": item.expense_period || '0',
              "amount": Number(item.amount).toFixed(4) + '' || '0',
              "price": item.price || '0',
              "priceDay": item.priceDayCopy || '0',
              "priceMonth": item.priceMonthCopy || '0',
              "late_fee_percent": item.late_fee / 100 + '' || '0',
              "expense_type": item.expense_type,
              "custom_period": item.customPeriod.length ? JSON.parse(JSON.stringify(item.customPeriod)) : '#',
              "units_code": item.unitsCode.length ? item.unitsCode + '' : '#',
              "units_val": item.unitsVal || '#',
              "payment_date_config": '#',
              "commission_date_boa": '#',
              "commission_date_fix_type": '#',
              "commission_date_fix_num": this.billDate.naturalDay + '',
              "tax_percent": item.tax_percent ? (item.tax_percent / 100 + '') : '#',
              "expense_date": item.expense_type == 'O' ? item.end_date : '#',
              "expense_memo": item.memo || '#'
            }
            expenses.push(obj)
          }
        })
        if (this.haveGDflag && this.isGDZJflag) {
          expenses.push({
            "name": '固定租金',
            "period": '0',
            "amount": '0',
            "price": this.oPrice,
            "priceDay": this.dRent,
            "priceMonth": this.mRent,
            "late_fee_percent": this.rentBill.rentPercent ? this.rentBill.rentPercent / 100 + '' : '0', //押金滞纳金比列
            "expense_type": 'R',
            "custom_period": '#',
            "units_code": "#",
            "tax_percent": '#'
          })
        }
        if (this.haveYJflag && this.isYJflag) {
          expenses.push({
            "name": '押金',
            "period": this.rentBill.bet + '',
            "amount": this.yaTotal + '',
            "price": '0',
            "priceDay": '0',
            "priceMonth": '0',
            "late_fee_percent": this.rentBill.proportion ? this.rentBill.proportion / 100 + '' : '0', //押金滞纳金比列
            "expense_type": 'D',
            "custom_period": '#',
            "units_code": "#",
            "tax_percent": '#',
          })
        }
        if (this.haveYYECCflag && this.isYYECCflag) {
          expenses.push({
            "name": '营业额抽成',
            "period": this.paymentCycle + '',
            "amount": '0',
            "price": '0',
            "priceDay": '0',
            "priceMonth": '0',
            "late_fee_percent": '0',
            "expense_type": 'CM',
            "custom_period": '#',
            "units_code": "#",
            "payment_date_config": this.paymentTypeCode + '' || '#',
            "commission_date_boa": this.billDateQHcode + '' || '#',
            "commission_date_fix_type": this.billDaycode + '' || '#',
            "commission_date_fix_num": this.paymentTypeCode == 'BL' ? this.billDate.naturalDay + '' : this.dayNum + '',
            "tax_percent": '#'
          })
        }

        var lastStepData = JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_FIRST_STEP'))

        if (lastStepData.intent) {
          if (lastStepData.intent.intentDeductibleAmount) {
            this.intentDeductibleAmount = -Number(lastStepData.intent.intentDeductibleAmount)
          }
        }

        if (expenses.length < 1) {
          hl.toast('至少填写一个费项')
          return
        }
        data.expenses = expenses
        this.payplanData = data

        if (n == 1) {
          hlhttp.post({
            url: 'bill_plans',
            data: {
              contract: JSON.stringify(data.contract),
              expenses: JSON.stringify(data.expenses)
            },
            success: (data) => {
              console.log(data)
              this.payData = data
            }
          })
        }
        this.isPayBillFlag = true
        setTimeout(() => {
          console.log(this.$refs.payPlan)
          let arr = this.$refs.payPlan.subtotalArr.R || []
          arr.map(item => {
            if (item.name == "固定租金") {
              this.contractAmount = item.expense
            }
          })
          if (this.breakPriceFlag == 'CR') {
            this.isSatisfyMinPrice()
          }
        }, 500)
      },
      //保存
      saveContract: function (n, id) {
        if (!this.isRequiredDate()) {
          return
        }
        if (this.haveGDflag && this.isGDZJflag) {
          if (!this.isRequiredGDZJ()) {
            return
          }
        }
        if (this.haveYJflag && this.isYJflag) {
          if (!this.isRequiredYJ()) {
            return
          }
        }
        if (this.haveGDflag && this.isGDZJflag) {
          if (!this.isRequiredJTZJ()) {
            return
          }
        }
        if (this.haveYYECCflag && this.isYYECCflag) {
          if (!this.isRequiredYYECC()) {
            return
          }
        }
        if (this.freePeriod.length) {
          if (!this.isRequiredMZQ()) {
            return
          }
        }
        if (!this.isCompleteFX()) {
          return
        }

        var data = {}

        let new_custom_config_property = []
        console.log(this.getCtPrevData.tmpData)
        this.getCtPrevData.tmpData.map(item => {
          new_custom_config_property.push({
            component_code: item.componentCode,
            component_type: item.componentType,
            property: item.property
          })
        })


        data.page_customize_component_biz_content = JSON.stringify(new_custom_config_property)
        data.custom_config_property = JSON.stringify(this.getCtPrevData.ZDYdata)

        data.m_code = this.getCtPrevData.zlfData.m_code || '#';
        data.c_code = this.getCtPrevData.zlfData.c_code || '#';
        data.memo = this.getCtPrevData.zlfData.memo || '#';
        data.name = this.getCtPrevData.zlfData.name || '#';
        data.contract_type = this.getCtPrevData.contactType.active;
        data.operator_id = JSON.parse(window.localStorage.getItem('userMes')).id;
        data.operator_name = JSON.parse(window.localStorage.getItem('userMes')).name;
        if (this.getCtPrevData.intent.id) {
          data.intent_id = this.getCtPrevData.intent.id
        }
        var zlfinfo = {
          zlf_type: this.getCtPrevData.zlfType.active,
          zlf_id: this.getCtPrevData.zlfData.zlf_id || '#',
          zlf_name: this.getCtPrevData.zlfData.zlf_name,
          zlf_lperson: this.getCtPrevData.zlfData.zlf_lperson || '#',
          zlf_sperson: this.getCtPrevData.zlfData.zlf_sperson,
          zlf_lphone: this.getCtPrevData.zlfData.zlf_lphone || '#',
          zlf_sphone: this.getCtPrevData.zlfData.zlf_sphone,
          zlf_industry_type: this.getCtPrevData.industryTypes.active,
          zlf_address: this.getCtPrevData.zlfData.zlf_address || '#',
          short_name: this.getCtPrevData.zlfData.shortName,
          idcode: this.getCtPrevData.zlfData.idcode,
          email: this.getCtPrevData.zlfData.email || '#',
          channel_category_code: this.getCtPrevData.channelType.selected.code || '#',
          channel_name_code: this.getCtPrevData.channelName.selected.code || '#',
          channel_name_value: this.getCtPrevData.channelName.selected.name || '#'
        }

        data.zlf_info = JSON.stringify(zlfinfo);
        data.project_info = {};
        data.project_info.project_id = this.getCtPrevData.projectInfo.project_id;
        data.project_info.project_name = this.getCtPrevData.projectInfo.project_name;

        if (this.getCtPrevData.projectInfo.units.length > 0) {
          var unitsArr = []

          for (var u = 0; u < this.getCtPrevData.projectInfo.units.length; u++) {
            var unitR = this.getCtPrevData.projectInfo.units[u];
            unitsArr.push({
              "building_id": unitR.building_id,
              "building_name": unitR.building_name,
              "floor_id": unitR.floor_id,
              "floor_num": unitR.floor_num ? unitR.floor_num.toString() : '#',
              "floor_name": unitR.floor_name,
              "unit_id": unitR.unit_id,
              "unit_name": unitR.unit_name,
              "unit_acreage": unitR.unit_acreage ? unitR.unit_acreage.toString() : '#',
							business_type: unitR.business_type,
            })
          }

          data.project_info.units = JSON.stringify(unitsArr);
        } else {
          data.project_info.units = '#';
        }

        if (this.wpNum > 0) {
          var wps = this.getCtPrevData.projectInfo.wpdata;
          var wpsArr = []

          for (var w = 0; w < wps.length; w++) {
            for (var p = 0; p < wps[w].stop.length; p++) {
              wpsArr.push({
                building_id: wps[w].building_id,
                building_name: wps[w].building_name,
                floor_id: wps[w].floor_id,
                floor_num: wps[w].floor_num ? wps[w].floor_num.toString() : '#',
                floor_name: wps[w].floor_name,
                wp_acreage: '0',
                unit_id: wps[w].unit_id,
                unit_name: wps[w].unit_name,
                "wp_id": wps[w].stop[p].stop_id || wps[w].stop[p].positionId,
                "wp_name": wps[w].stop[p].stop_name || wps[w].stop[p].positionName,
								business_type: wps[w].stop[p].business_type,
              })
            }
          }
          data.project_info.wps = JSON.stringify(wpsArr);
        } else {
          data.project_info.wps = '#'
        }

        if (this.stNum > 0) {
          var sts = this.getCtPrevData.projectInfo.stdata;
          var stsArr = []

          for (var s = 0; s < sts.length; s++) {
            for (var t = 0; t < sts[s].stop.length; t++) {
              stsArr.push({
                building_id: sts[s].building_id,
                building_name: sts[s].building_name,
                floor_id: sts[s].floor_id,
                floor_num: sts[s].floor_num ? sts[s].floor_num.toString() : '#',
                floor_name: sts[s].floor_name,
                stop_acreage: '0',
                unit_id: sts[s].unit_id,
                unit_name: sts[s].unit_name,
                "stop_id": sts[s].stop[t].stop_id || sts[s].stop[t].positionId,
                "stop_name": sts[s].stop[t].stop_name || sts[s].stop[t].positionName,
								business_type: sts[s].stop[t].business_type,
              })
            }
          }
          data.project_info.stops = JSON.stringify(stsArr);
        } else {
          data.project_info.stops = '#'
        }

        data.project_info = JSON.stringify(data.project_info);
        data.rent_info = {} || '#';
        data.rent_info.rent_way = this.setRent.active + '';
        data.rent_info.rent_price = this.rentBill.oPrice ? this.rentBill.oPrice.toString() : '0';
        data.rent_info.rent_price_day = this.rentBill.dRent ? this.rentBill.dRent.toString() : '0';
        data.rent_info.rent_price_month = this.rentBill.mRent ? this.rentBill.mRent.toString() : '0';
        data.rent_info.bill_date_fix_num = this.billDate.naturalDay + '';
        data.rent_info.sign_time = this.signingDate || '';
        data.rent_info.deposit = this.yaTotal || '0';
        data.rent_info.deposit_period = this.rentBill.bet ? this.rentBill.bet.toString() : '0';
        data.rent_info.payment_period = this.rentBill.pay ? this.rentBill.pay.toString() : '0';
        data.rent_info.begin_date = this.beginDate;
        data.rent_info.end_date = this.endDate;
        data.rent_info.bill_date_BOA = this.billDate.BFCode + '';
        data.rent_info.bill_date_fix_type = this.billDate.dayCode + '';
        data.rent_info.first_payment_date = this.SQdate;
        data.rent_info.rent_increase_way = this.ladderRentActive + '';

				data.not_update_info_list = JSON.stringify(this.not_update_info_list)
        if (hlUrlUtil.GetQueryString('relet')) {
          if (hlUrlUtil.GetQueryString('relet') == 'true') {
            data.renew_contract_id = hlUrlUtil.GetQueryString('id')
          }
        }

        let free_dates = []
        this.freePeriod.map(item => {
          free_dates.push({
            free_begin_date: item.btime,
            free_end_date: item.etime,
            bill_hidden_flag: item.flag.length ? 'Y' : 'N',
            free_memo: item.memo,
          })
        })

        data.rent_info.free_dates = free_dates.length ? JSON.stringify(free_dates) : '#'
        data.rent_info.intermediary_commission = this.intermediaryCommission4 + '' || '#'
        data.rent_info.intermediary_commission_percent = this.intermediaryCommissionPercent ? this.intermediaryCommissionPercent / 100 + '' : '0'

        // 折扣月租金
        if (this.haveYZJ) {
          data.rent_info.rent_discount_rate = this.rentDiscount4Rate ? (this.rentDiscount4Rate / 100).toFixed(6) : '#'
          data.rent_info.rent_discount_price_day = this.rentDiscount4PriceDay || '#'
          data.rent_info.rent_discount_price_month = this.rentDiscount4PriceMonth || '#'

          let arr1 = [this.rentDiscount4Rate ? (this.rentDiscount4Rate / 100).toFixed(6) : ''] //阶梯租金的折扣率
          let arr2 = [this.rentDiscount4PriceDay] //阶梯租金的日租金
          let arr3 = [this.rentDiscount4PriceMonth] //阶梯租金的月租金

          this.copyRentLadderArr.map(item => {
            arr1.push((item.dis / 100).toFixed(6))
            arr2.push(item.disD)
            arr3.push(item.disM)
          })

          data.rent_info.rent_increse_discount_rate = arr1 + ''
          data.rent_info.rent_increse_discount_day = arr2 + ''
          data.rent_info.rent_increse_discount_month = arr3 + ''
        }
        data.rent_info.effective_rent_day = this.effective_rent_day + '' || '#'
        data.rent_info.effective_rent_month = this.effective_rent_month + '' || '#'
        let rDate = [] //递增时间
        let rRate = [] //租金递增率
        let price = [] //单价
        let rDay = [] //日递增租金
        let rMonth = [] //月递增租金
        rDay.push(this.rentBill.dRent)
        rMonth.push(this.rentBill.mRent)
        rDate.push(this.beginDate)
        rRate.push('0')
        price.push(this.rentBill.oPrice)

        this.copyRentLadderArr.map(item => {
          rDay.push(item.rz)
          rMonth.push(item.yz)
          rRate.push(item.lv)
          price.push(item.dj)
        })
        this.rentLadder.map(item => {
          rDate.push(item.time)
        })
        data.rent_info.rent_increse_price = price.length ? price + '' : '#'
        data.rent_info.rent_increse_date = rDate.length ? rDate + '' : '#'
        data.rent_info.rent_increse_day = rDay.length ? rDay + '' : '#'
        data.rent_info.rent_increse_month = rMonth.length ? rMonth + '' : '#'
        data.rent_info.rent_increse_percent = rRate + ''

        if (this.setUnit.nIndex + '' == 0) {
          data.rent_info.rent_price_unit = 'D'
        } else {
          data.rent_info.rent_price_unit = 'M'
        }

        data.rent_info.rent_late_fee = this.rentBill.rentPercent ? this.rentBill.rentPercent + '' : '0';
        data.rent_info = JSON.stringify(data.rent_info);
        this.costItem.map((item, index) => {
          if (item.expense_type == 'T') {
            item.expense_flow_type = item.amount > 0 ? 'RC' : 'RF'
          } else {
            item.expense_flow_type = 'RC'
          }
        })
        var newArr = []
        this.costItem.map(item => {
          item.units_val = item.unitsVal || '#'
          if (item.expense_type == 'P' || item.expense_type == 'O' || item.expense_type == 'T' || item.expense_type == 'D') {
            newArr.push(item)
          }
        })
        var costItemArr = JSON.parse(JSON.stringify(newArr));

        for (var i = 0; i < costItemArr.length; i++) {
          if (costItemArr[i].expense_type == 'O') {
            costItemArr[i].deposit_type = '#'
            costItemArr[i].expense_date = costItemArr[i].end_date || '#'
            costItemArr[i].expense_memo = costItemArr[i].memo || '#'
          }
          if (costItemArr[i].expense_type == 'D') {
            costItemArr[i].deposit_type = 'DO'
          }
          // 若果为固定租金  则根据页面所填写租金计算
          costItemArr[i].priceDay = JSON.parse(JSON.stringify(costItemArr[i].priceDayCopy))
          costItemArr[i].priceMonth = JSON.parse(JSON.stringify(costItemArr[i].priceMonthCopy))
          costItemArr[i].units_code = costItemArr[i].unitsCode.length ? costItemArr[i].unitsCode + '' : '#'

          if (costItemArr[i].amount == '') {
            costItemArr[i].amount = '0'
          }
          if (costItemArr[i].price == '') {
            costItemArr[i].price = '0'
          }
          if (costItemArr[i].priceDay == '') {
            costItemArr[i].priceDay = '0'
          }
          if (costItemArr[i].priceMonth == '') {
            costItemArr[i].priceMonth = '0'
          }
          if (costItemArr[i].expense_period == '') {
            costItemArr[i].expense_period = '0'
          }

          costItemArr[i].tax_percent = costItemArr[i].tax_percent ? costItemArr[i].tax_percent / 100 + '' : '#'

          if (costItemArr[i].late_fee == '') {
            costItemArr[i].late_fee_percent = '0'
          } else {
            costItemArr[i].late_fee_percent = (Number(costItemArr[i].late_fee.replace('%', '')) / 100).toString()
          }
          if (!costItemArr[i].customPeriod) {
            costItemArr[i].custom_period = []
          }
          if (!costItemArr[i].customPeriod.length) {
            costItemArr[i].custom_period = '#'
          }
          if (costItemArr[i].customPeriod.length) {
            costItemArr[i].custom_period = costItemArr[i].customPeriod
          }
          delete costItemArr[i].customPeriod;
        }
        // 将固定租金和租金押金加入费项中
        if (this.haveGDflag && this.isGDZJflag) {
          costItemArr.push({
            'amount': '0',
            'custom_period': '#',
            "expense_name": '固定租金',
            'expense_flow_type': 'RC',
            "late_fee_percent": this.rentBill.rentPercent ? this.rentBill.rentPercent / 100 + '' : '0', //租金滞纳金比列
            'expense_period': '0',
            'expense_type': 'R',
            'late_fee': '0',
            'priceDayCopy': '',
            'price': this.oPrice,
            "priceDay": this.dRent,
            "priceMonth": this.mRent,
            'priceMonthCopy': '',
            'units_code': '#',
            "tax_percent": '#'
          })
        }
        if (this.haveYJflag && this.isYJflag && this.haveGDflag && this.isGDZJflag) {
          costItemArr.push({
            'amount': this.rentBill.menoy,
            'custom_period': '#',
            "expense_name": '押金',
            'expense_flow_type': 'RC',
            "late_fee_percent": this.rentBill.proportion ? this.rentBill.proportion / 100 + '' : '0', //租金滞纳金比列
            'expense_period': this.rentBill.bet + '',
            'expense_type': 'D',
            'late_fee': '0',
            'priceDayCopy': '',
            'price': '0',
            "priceDay": '0',
            "priceMonth": '0',
            'priceMonthCopy': '0',
            'units_code': '#',
            "tax_percent": '#',
            "deposit_type": 'DR',
          })
        }
        //营业额全部传0，类型 CM
        if (this.haveYYECCflag && this.isYYECCflag) {
          costItemArr.push({
            "amount": '0',
            "custom_period": '#',
            "expense_name": '营业额抽成',
            'expense_flow_type': 'RC',
            "late_fee_percent": '0',
            "expense_period": this.paymentCycle + '',
            "expense_type": 'CM',
            "price": '0',
            "priceDay": '0',
            "priceMonth": '0',
            "units_code": "#",
            "tax_percent": '#',
            "payment_date_config": this.paymentTypeCode.length ? this.paymentTypeCode + '' : '#',
            "commission_date_boa": this.billDateQHcode || '#',
            "commission_date_fix_type": this.billDaycode || '#',
            "commission_date_fix_num": this.paymentTypeCode == 'BL' ? this.billDate.naturalDay + '' : this.dayNum + ''
          })
        }

        data.expense = JSON.stringify(costItemArr);

        console.log(this.resData);
        this.resData.map(item => {
          item.expense_list.map(single => {
            if (single.expense_type == 'T') {
              single.expense_flow_type = Number(single.amount_reveice) > 0 ? 'RC' : 'RF'
            } else {
              single.expense_flow_type = 'RC'
            }
          })
        })
        data.bill_plans = JSON.stringify(this.resData);


        console.log(data.bill_plans);
        if (this.haveYYECCflag && this.isYYECCflag) {
          data.commission_info = {};
          let rules = [];
          this.tableArr.map(item => {
            rules.push({
              "base_val_down_limit": item.base_val_down_limit + '',
              "base_val_up_limit": item.base_val_up_limit + '',
              "commission_percent": item.commission_percent + '',
              "commission_down_limit": item.commission_down_limit ? item.commission_down_limit + '' : '#',
              "commission_up_limit": item.commission_up_limit ? item.commission_up_limit + '' : '#',
              "late_fee_percent": item.late_fee_percent ? item.late_fee_percent + '' : '#'
            })
          })
          rules[rules.length - 1].base_val_up_limit = '不限'
          let commission_info_data = {
            commission_type: this.turnoverCode + '',
            compare_rent_amt_flag: this.turnoverCheckBox,
            payment_period: this.paymentCycle || '#',
            payment_date_config: this.paymentTypeCode + '',
            commission_date_boa: this.paymentTypeCode == 'BL' ? this.billDate.BFCode + '' : this.billDateQHcode,
            commission_date_fix_type: this.paymentTypeCode == 'BL' ? this.billDate.dayCode + '' : this.billDaycode,
            commission_date_fix_num: this.paymentTypeCode == 'BL' ? this.billDate.naturalDay + '' : this.dayNum + '',
            rules: JSON.stringify(rules)
          }
          data.commission_info = JSON.stringify(commission_info_data) || '#'
        }
        //创建合同
        if (n == 1) {
          var that = this
          hlhttp.post({
            url: 'contract/_submit',
            data: data,
            success: function (res) {
              that.contractFile(res.id)
              hl.toast('生成合同成功');
              var keyArr = [
                'RENT_BU_UNIT_MES',
                'RENT_WP_POSITION_MES',
                'RENT_ST_POSITION_MES',
                'CREATED_CONTRACT_FIRST_STEP',
                'CREATED_CONTRACT_SECOND_STEP'
              ]
              hlStorage.ssClearMultipleKey(keyArr)
              hlUrlUtil.goTo('unitContractList', {
                ddtab: true
              })
            }
          })
        }
        //保存草稿
        if (n == 2) {
          var that = this
          hlhttp.post({
            url: 'contract',
            data: data,
            success: function (res) {
              that.contractFile(res.id, 'put')
              hl.toast('保存草稿成功');
              var keyArr = [
                'RENT_BU_UNIT_MES',
                'RENT_WP_POSITION_MES',
                'RENT_ST_POSITION_MES',
                'CREATED_CONTRACT_FIRST_STEP',
                'CREATED_CONTRACT_SECOND_STEP'
              ]
              hlStorage.ssClearMultipleKey(keyArr)
              hlUrlUtil.goTo('unitContractList', {
                ddtab: true
              })
            }
          })
        }
        //合同预览
        if (n == 3) {
          data.template_id = id
          var that = this
          hlhttp.post({
            baseUrl: exclUrl,
            url: 'contract/contract_content_tempalte/preview_advance',
            data: data,
            success: function (res) {
              $.previewPDF(res.pdf_url)
            }
          })
        }
        //合同下载
        if (n == 4) {
          data.template_id = this.selectedTemList
          data.file_type = this.selectedTemTypeList.join(',')
          var that = this
          hlhttp.post({
            baseUrl: exclUrl,
            url: 'contract/contract_content_tempalte/preview_export',
            data: data,
            success: function (res) {
              that.downloadFiles(res)
              that.TemplateModulShow = false
            }
          })
        }
        // 保存合同（续租）
        if (n == 5) {
          var that = this
          hlhttp.post({
            url: 'contract/_submit',
            data: data,
            success: (res) => {
              that.contractFile(res.id)
              hl.toast('生成合同成功');
              var keyArr = [
                'CREATED_CONTRACT_FIRST_STEP',
                'CREATED_CONTRACT_SECOND_STEP'
              ]
              hlStorage.ssClearMultipleKey(keyArr)
              hlUrlUtil.goTo('contractNewDeatil', {
                id: this.contractId,
                proId: this.getCtPrevData.projectInfo.project_id.toString(),
                ddtab: true
              })
            }
          })
        }
        // 保存合同（编辑）
        if (n == 6) {
          data.id = this.contractId
          var that = this
          hlhttp.post({
            url: 'contract/_edit',
            data: data,
            success: (res) => {
              that.contractFile(that.contractId, 'put')

              hl.toast('保存合同成功');
              var keyArr = [
                'CREATED_CONTRACT_FIRST_STEP',
                'CREATED_CONTRACT_SECOND_STEP'
              ]
              hlStorage.ssClearMultipleKey(keyArr)
              hlUrlUtil.goTo('contractNewDeatil', {
                id: this.contractId,
                proId: this.getCtPrevData.projectInfo.project_id.toString(),
                ddtab: true
              })
            }
          })
        }
      },
      // 附带文件（上传文件）
      contractFile(id, type) {

        let fileList = window.sessionStorage.getItem('contract_upload_file') ? JSON.parse(window.sessionStorage.getItem('contract_upload_file')) : []

        let nameList = []
        let urlList = []

        fileList.forEach(item => {
          nameList.push(item.name)
          urlList.push(item.url)
        })

        let data = {
          contract_id: id,
          attachment_names: fileList.length ? nameList.join(',') : '#',
          attachment_url: fileList.length ? urlList.join(',') : '#',
        }
        if (type == 'put') {
          hlhttp.put({
            url: 'contract_attachment',
            data: data,
            success: function () {
              window.sessionStorage.removeItem('contract_upload_file')
              // hl.toast('上传成功')
            }
          })
        } else {
          hlhttp.post({
            url: 'contract_attachment',
            data: data,
            success: function () {
              window.sessionStorage.removeItem('contract_upload_file')
              // hl.toast('上传成功')
            }
          })
        }

      },
      //获取费项
      getCostItem: function () {
        var that = this;
        hlhttp.get({
          url: 'project/config_expenditures',
          data: {
            project_id: that.getCtPrevData.projectInfo.project_id
          },
          success: function (res) {
            if (JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_SECOND_STEP'))) {
              that.costItem = JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_SECOND_STEP')).costItem;
              return
            }
            res.map(item => {
              if (item.type == 'R') {
                that.isGDZJflag = true
              }
              if (item.type == 'D') {
                that.isYJflag = true
              }
              if (item.type == 'CM') {
                that.isYYECCflag = true
              }
              if (item.type == 'P' || item.type == 'O') {
                that.costItem.push({
                  unitsVal: item.unitsVal ? item.unitsVal : '',
                  unitsCode: item.unitsCode ? [item.unitsCode] : [],
                  expense_code: [item.id],
                  expense_name: item.name,
                  amount: '',
                  price: '',
                  priceDay: '',
                  priceMonth: '',
                  priceDayCopy: '',
                  priceMonthCopy: '',
                  expense_period: '',
                  expense_type: item.type,
                  late_fee: item.lateFee,
                  customPeriod: [],
                  tax_percent: ''
                })
              }
            })
            // 去重啊
            that.costItem = hlArrayUtil.removeRepeat(that.costItem, 'expense_name');

            console.log(that.costItem );
          }
        })
      },
      // 获取折扣月租金配置
      getYZJconfig() {
        let data = {
          module_code: 'CIWU',
          config_name: 'CW_RENT_DISCOUNT_TYPE_CONFIG',
        }
        hlhttp.get({
          url: 'configure/dict',
          data: data,
          success: res => {
            if (res[0].dictValue == 'CONTRASTRENT') {
              this.haveYZJ = true
            }
          }
        })
      },
      // 折扣月租金固定租金板块计算
      setYZJitem(type) {
        if (this.rentDiscountRate && this.rentDiscountPriceDay && this.rentDiscountPriceMonth) {
          this.rentDiscount4Rate = Number(this.rentDiscountRate).toFixed(4)
          this.rentDiscount4PriceDay = Number(this.rentDiscountPriceDay).toFixed(4)
          this.rentDiscount4PriceMonth = Number(this.rentDiscountPriceMonth).toFixed(4)
        } else {
          if (type == 's') {
            if (!this.rentDiscountRate) return
            this.rentDiscount4Rate = Number(this.rentDiscountRate).toFixed(4)
            this.rentDiscountPriceDay = (this.rentBill.dRent * this.rentDiscountRate / 100).toFixed(2)
            this.rentDiscount4PriceDay = (this.rentBill.dRent * this.rentDiscountRate / 100).toFixed(4)
            this.rentDiscountPriceMonth = (this.rentBill.mRent * this.rentDiscountRate / 100).toFixed(2)
            this.rentDiscount4PriceMonth = (this.rentBill.mRent * this.rentDiscountRate / 100).toFixed(4)
          }
          if (type == 'd') {
            if (!this.rentDiscountPriceDay) return
            this.rentDiscount4PriceDay = Number(this.rentDiscountPriceDay).toFixed(4)
            this.rentDiscountRate = (this.rentDiscountPriceDay / this.rentBill.dRent * 100).toFixed(2)
            this.rentDiscount4Rate = (this.rentDiscountPriceDay / this.rentBill.dRent * 100).toFixed(4)
            this.rentDiscountPriceMonth = (this.rentBill.mRent * this.rentDiscountRate / 100).toFixed(2)
            this.rentDiscount4PriceMonth = (this.rentBill.mRent * this.rentDiscountRate / 100).toFixed(4)
          }
          if (type == 'm') {
            if (!this.rentDiscountPriceMonth) return
            this.rentDiscount4PriceMonth = Number(this.rentDiscountPriceMonth).toFixed(4)
            this.rentDiscountRate = (this.rentDiscountPriceMonth / this.rentBill.mRent * 100).toFixed(2)
            this.rentDiscount4Rate = (this.rentDiscountPriceMonth / this.rentBill.mRent * 100).toFixed(4)
            this.rentDiscountPriceDay = (this.rentBill.dRent * this.rentDiscountRate / 100).toFixed(2) + ''
            this.rentDiscount4PriceDay = (this.rentBill.dRent * this.rentDiscountRate / 100).toFixed(4) + ''
          }
        }
      },
      // 折扣月租金固定阶梯租金计算
      setJTitem(i, type) {
        let rentData = this.rentLadder[i]
        let rentCopyData = this.copyRentLadderArr[i]

        if (rentData.dis && rentData.disD && rentData.disM) {
          rentCopyData.dis = Number(rentData.dis).toFixed(4)
          rentCopyData.disD = Number(rentData.disD).toFixed(4)
          rentCopyData.disM = Number(rentData.disM).toFixed(4)
        } else {
          if (type == 's') {
            if (!rentData.dis && rentData.dis != '0') {
              rentCopyData.dis = ''
              return
            }
            rentCopyData.dis = Number(rentData.dis).toFixed(4)
            rentData.disD = (rentCopyData.rz * rentData.dis / 100).toFixed(2) + ''
            rentCopyData.disD = (rentCopyData.rz * rentData.dis / 100).toFixed(4) + ''
            rentData.disM = (rentCopyData.yz * rentData.dis / 100).toFixed(2) + ''
            rentCopyData.disM = (rentCopyData.yz * rentData.dis / 100).toFixed(4) + ''
          }
          if (type == 'd') {
            if (!rentData.disD && rentData.disD != '0') {
              rentCopyData.disD = ''
              return
            }
            rentCopyData.disD = Number(rentData.disD).toFixed(4)
            rentData.dis = (rentCopyData.disD / rentCopyData.rz * 100).toFixed(2)
            rentCopyData.dis = (rentCopyData.disD / rentCopyData.rz * 100).toFixed(4)
            rentData.disM = (rentCopyData.yz * (rentCopyData.disD / rentCopyData.rz)).toFixed(2)
            rentCopyData.disM = (rentCopyData.yz * (rentCopyData.disD / rentCopyData.rz)).toFixed(4)
          }
          if (type == 'm') {
            if (!rentData.disM && rentData.disM != '0') {
              rentCopyData.disM = ''
              return
            }
            rentCopyData.disM = Number(rentData.disM).toFixed(4)
            rentData.dis = (rentCopyData.disM / rentCopyData.yz * 100).toFixed(2)
            rentCopyData.dis = (rentCopyData.disM / rentCopyData.yz * 100).toFixed(4)
            rentData.disD = (rentCopyData.rz * (rentCopyData.disM / rentCopyData.yz)).toFixed(2)
            rentCopyData.disD = (rentCopyData.rz * (rentCopyData.disM / rentCopyData.yz)).toFixed(4)
          }
        }
      },

      // 获取合同详情
      getContractDetail: function () {
        var self = this;
        let url = 'contract'
        let data = {
          id: self.contractId
        }
        if (hlUrlUtil.GetQueryString('relet') == 'true') {
          url = 'contract/renewal'
          data = {
            contract_id: self.contractId
          }
        }
        hlhttp.get({
          url: url,
          data: data,
          success: function (data) {
            self.contractDetail = data
            var prevData = self.getCtPrevData;
            ///续租(固定租金+日期)
            if (self.reletFlag) {
              self.SQdate = data.firstPaymentDate ? hlDateUtil.formatUTCDate(data.firstPaymentDate, 'yyyy-MM-dd') : hlDateUtil.formatUTCDate((new Date()).getTime(), 'yyyy-MM-dd')
              self.signingDate = data.signingDate ? hlDateUtil.formatUTCDate(data.signTime, 'yyyy-MM-dd') : hlDateUtil.formatUTCDate((new Date()).getTime(), 'yyyy-MM-dd')
              self.beginDate = data.beginDate ? hlDateUtil.formatUTCDate(data.beginDate, 'yyyy-MM-dd') : hlDateUtil.formatUTCDate((new Date()).getTime(), 'yyyy-MM-dd')
              self.endDate = data.endDate ? hlDateUtil.formatUTCDate(data.endDate, 'yyyy-MM-dd') : ''
              self.rentBill = {
                'oPrice': Number(data.rentPrice).toFixed(4) + '',
                'dRent': Number(data.rentPriceDay).toFixed(4) + '',
                'mRent': Number(data.rentPriceMonth).toFixed(4) + '',
                'rentPercent': data.rentLateFeePercent + '',
                'menoy': Number(data.deposit).toFixed(4) + '',
                'bet': data.depositPeriod + '',
                'pay': data.paymentPeriod + '',
              }
              self.billDate.BFCode = [data.billDateBOA]
              self.billDate.dayCode = [data.billDateFixType]
              self.oPrice = Number(data.rentPrice).toFixed(2) + '';
              self.dRent = Number(data.rentPriceDay).toFixed(2) + '';
              self.mRent = Number(data.rentPriceMonth).toFixed(2) + '';
              self.menoy = Number(data.deposit).toFixed(2) + '';
              self.setRent.active = [data.rentWay];
              if (data.rentPriceUnit === 'D') self.setUnit.nIndex = ['0'];
              if (data.rentPriceUnit === 'M') self.setUnit.nIndex = ['1'];
              if (data.rentPrice) {
                self.haveGDflag = true
                self.isGDZJflag = true
              }
              if (data.deposit) {
                self.isYJflag = true
                self.haveYJflag = true
              }
            }
            //合同编辑
            if (!self.reletFlag) {
              if (data.intermediaryCommissionPercent) {
                self.commissionStatus = data.intermediaryCommissionPercent ? 'Y' : 'N'
                self.intermediaryCommissionPercent = data.intermediaryCommissionPercent * 100
                self.intermediaryCommission = data.intermediaryCommission
              }
              self.beginDate = hlDateUtil.formatUTCDate(data.beginDate, 'yyyy-MM-dd')
              self.endDate = hlDateUtil.formatUTCDate(data.endDate, 'yyyy-MM-dd')
              self.signingDate = hlDateUtil.formatUTCDate(data.signTime, 'yyyy-MM-dd')
              self.SQdate = hlDateUtil.formatUTCDate(data.firstPaymentDate, 'yyyy-MM-dd')
              if (prevData.contactType.active === data.contractType && Number(self.utAge).toFixed(2) == Number(data.rentAcreage).toFixed(2) && self.wpNum == data.rentWpCount) {
                // 租金押金
                let num = 0
                if (data.expenses.length) {
                  data.expenses.map(item => {
                    if (item.expenseType == 'D' && item.depositType == 'DO') {
                      num = num + Number(item.amount)
                    }
                  })
                }
                self.ladderRentActive = [data.rentIncreaseWay]
                self.rentBill = {
                  'oPrice': Number(data.rentPrice).toFixed(4) + '',
                  'dRent': Number(data.rentPriceDay).toFixed(4) + '',
                  'mRent': Number(data.rentPriceMonth).toFixed(4) + '',
                  'rentPercent': data.rentLateFeePercent,
                  'menoy': (Number(data.deposit) - num).toFixed(4) + '',
                  'bet': data.depositPeriod + '',
                  'pay': data.paymentPeriod + '',
                }
                self.billDate.naturalDay = data.billDateFixNum
                self.billDate.BFCode = [data.billDateBOA]
                self.billDate.dayCode = [data.billDateFixType]
                self.oPrice = Number(data.rentPrice).toFixed(2) + '';
                self.dRent = Number(data.rentPriceDay).toFixed(2) + '';
                self.mRent = Number(data.rentPriceMonth).toFixed(2) + '';
                self.menoy = (Number(data.deposit) - num).toFixed(2) + '';
                self.setRent.active = [data.rentWay];
                if (data.rentPriceUnit === 'D') self.setUnit.nIndex = ['0'];
                if (data.rentPriceUnit === 'M') self.setUnit.nIndex = ['1'];
                // 折扣月租金
                if (data.rentDiscountRate) {
                  self.haveYZJ = true
                  self.rentDiscountRate = (data.rentDiscountRate * 100).toFixed(2)
                  self.rentDiscount4Rate = (data.rentDiscountRate * 100).toFixed(4)
                  self.rentDiscountPriceDay = data.rentDiscountPriceDay.toFixed(2)
                  self.rentDiscount4PriceDay = data.rentDiscountPriceDay.toFixed(4)
                  self.rentDiscountPriceMonth = data.rentDiscountPriceMonth.toFixed(2)
                  self.rentDiscount4PriceMonth = data.rentDiscountPriceMonth.toFixed(4)
                }
                // 阶梯租金

                if (data.rentIncreseDate.split(',').length > 1) {
                  var rentArr = [];
                  var rentIndex = 1;
                  data.rentIncreseDate.split(',').map(function (_item) {
                    if (rentIndex < data.rentIncreseDate.split(',').length) {
                      rentArr.push({
                        'time': data.rentIncreseDate.split(',')[rentIndex],
                        'lv': data.rentIncresePercent.split(',')[rentIndex],
                        'dj': data.rentIncresePrice.split(',')[rentIndex],
                        'rz': data.rentIncreseDay.split(',')[rentIndex],
                        'yz': data.rentIncreseMonth.split(',')[rentIndex],
                        'dis': '',
                        'disD': '',
                        'disM': '',
                      })
                      rentIndex++;
                    }
                  })

                  rentArr.map(item => {
                    item.dj = Number(item.dj).toFixed(2)
                    item.rz = Number(item.rz).toFixed(2)
                    item.yz = Number(item.yz).toFixed(2)
                    self.rentLadder.push(JSON.parse(JSON.stringify(item)))
                  })
                  // 折扣月租金
                  if (data.rentIncreseDiscountRate) {
                    let arr1 = data.rentIncreseDiscountRate.split(',')
                    console.log(arr1)
                    let arr2 = data.rentIncreseDiscountDay.split(',')
                    let arr3 = data.rentIncreseDiscountMonth.split(',')
                    self.rentLadder.map((item, index) => {
                      item.dis = Number(arr1[index + 1] * 100).toFixed(2)
                      item.disD = Number(arr2[index + 1]).toFixed(2)
                      item.disM = Number(arr3[index + 1]).toFixed(2)
                    })
                    rentArr.map((item, index) => {
                      item.dis = Number(arr1[index + 1] * 100).toFixed(4)
                      item.disD = arr2[index + 1]
                      item.disM = arr3[index + 1]
                    })
                  }
                  self.copyRentLadderArr = JSON.parse(JSON.stringify(rentArr));
                }
              }
              //营业额
              if (data.commissionPaymentPeriod) {
                self.turnoverCode = [data.commissionTypeCode]
                self.paymentTypeCode = [data.paymentDateConfig]
                self.billDateQHcode = [data.billDateBOA]
                self.billDaycode = data.billDateFixType
                self.dayNum = data.commissionDateFixNum
                if (data.commissionRules.length) {
                  self.paymentCycle = data.commissionPaymentPeriod
                  self.turnoverCheckBox = data.compareRentAmtFlag
                  self.paymentTypeCode = data.paymentDateConfig
                  self.billDateQHcode = data.commissionDateBoa
                  self.billDaycode = data.commissionDateFixType
                  self.dayNum = data.commissionDateFixNum
                  self.tableArr = []
                  data.commissionRules.map((item, index) => {
                    self.tableArr.push({
                      base_val_down_limit: item.baseValDownLimit,
                      base_val_up_limit: index == data.commissionRules.length - 1 ? '' : item.baseValUpLimit,
                      commission_percent: item.commissonPercent,
                      commission_down_limit: item.commissionDownLimit,
                      commission_up_limit: item.commissionUpLimit,
                      late_fee_percent: item.lateFeePercent,
                    })
                  })
                }
                self.turnoverCheckBox = data.compareRentAmtFlag
                self.haveYYECCflag = true
                self.isYYECCflag = true
              }
              // 免租期
              if (data.freeDates) {
                // data.freeDate.split(',').map(function (_item) {
                //   self.freePeriod.push({ 'btime': _item.split('~')[0], 'etime': _item.split('~')[1] })
                // })
                data.freeDates.map(item => {
                  self.freePeriod.push({
                    btime: hlDateUtil.formatUTCDate(item.freeBeginDate, 'yyyy-MM-dd'),
                    etime: hlDateUtil.formatUTCDate(item.freeEndDate, 'yyyy-MM-dd'),
                    flag: item.billHiddenFlag == 'Y' ? ['Y'] : [],
                    memo: item.freeMemo || '',
                  })
                })
              }
              // 费项
              if (data.expenses) {
                data.expenses.map(function (_item) {
                  if (_item.expenseType == 'R') {
                    self.haveGDflag = true
                    self.isGDZJflag = true
                  }
                  if (_item.expenseType == 'D') {
                    self.isYJflag = true
                    self.haveYJflag = true
                    self.rentBill.proportion = _item.lateFee * 100
                  }
                  var arr = []
                  _item.customPeriod.map(function (val) {
                    arr.push({
                      begin_date: hlDateUtil.formatUTCDate(val.beginDate, 'yyyy-MM-dd'),
                      end_date: hlDateUtil.formatUTCDate(val.endDate, 'yyyy-MM-dd')
                    })
                  })
                  if (!(_item.expenseType == 'D' && (_item.depositType == 'DR' || !_item.depositType))) {
                    self.costItem.push({
                      'expense_name': _item.expenseName,
                      'price': Number(_item.price).toFixed(2) + '',
                      'amount': _item.amount || _item.amount == 0 ? _item.amount.toString() : '',
                      'priceDay': Number(_item.priceDay).toFixed(2) + '',
                      'priceMonth': Number(_item.priceMonth).toFixed(2) + '',
                      'priceDayCopy': _item.priceDay || _item.priceDay == 0 ? _item.priceDay.toString() : '',
                      'priceMonthCopy': _item.priceMonth || _item.priceMonth == 0 ? _item.priceMonth.toString() : '',
                      'expense_period': _item.expensePeriod,
                      'late_fee': Number(_item.lateFee * 100).toFixed(2),
                      'expense_type': _item.expenseType,
                      'customPeriod': arr,
                      'unitsVal': _item.unitsVal ? _item.unitsVal : '',
                      'unitsCode': _item.unitsCode ? [_item.unitsCode] : [],
                      'expense_code': [_item.expenditureId],
                      'tax_percent': (_item.taxPercent * 100) + '',
                      'end_date': _item.expenseType == 'O' ? hlDateUtil.formatUTCDate(_item.expenseDate, 'yyyy-MM-dd') : '',
                      'memo': _item.expenseMemo || ''
                    })
                  }
                })
              }

              self.getCostItem();
            }

          }
        })
      },

      putPlayData() {
        let data = {}
        let free_dates = []

        this.freePeriod.map(item => {
          free_dates.push({
            free_begin_date: item.btime,
            free_end_date: item.etime,
            bill_hidden_flag: item.flag.length ? 'Y' : 'N',
            free_memo: item.memo,
          })
        })

        let rDate = [] //递增时间
        let rRate = [] //租金递增率
        let price = [] //单价
        let rDay = [] //日递增租金
        let rMonth = [] //月递增租金
        rDay.push(this.rentBill.dRent)
        rMonth.push(this.rentBill.mRent)
        rDate.push(this.beginDate)
        this.copyRentLadderArr.map(item => {
          rDay.push(item.rz)
          rMonth.push(item.yz)
          rRate.push(item.lv)
          price.push(item.dj)
        })
        this.rentLadder.map(item => {
          rDate.push(item.time)
        })
        data.contract = {
          "rent_way": this.setRent.active + '', //租金计算方式，M按月计算、D按天计算
          "period": this.rentBill.pay + '' || '#', //付款周期
          // "free_date": mdate.length ? mdate + '' : '#',  //免租期
          "free_dates": free_dates.length ? JSON.stringify(free_dates) : '#',
          "rent_late_fee_percent": this.rentBill.rentPercent ? (this.rentBill.rentPercent / 100 + '') : '0', //租金滞纳金比例
          "rent_increse_days": rDay.length ? (rDay + '') : '', //日递增租金
          "rent_increse_months": rMonth.length ? (rMonth + '') : '', //月递增租金
          "rent_increse_dates": rDate.length ? (rDate + '') : '', //租金递增日期
          "begin_date": this.beginDate, //合同开始日期
          "end_date": this.endDate, //合同结束日期
          "first_payment_date": this.SQdate, //首期付款日
          "bill_date_BOA": this.billDate.BFCode + '', //账单提醒日 B 账期开始前 A 账期开始后
          "bill_date_fix_type": this.billDate.dayCode + '', //账单提醒日 类型 RQ 固定日期 TS 天数
          "bill_date_fix_num": this.billDate.naturalDay + '', //账单提醒日 指定天数/指定日期
          "rent_increase_way": this.ladderRentActive + '' //租金递增计算方式 C当日计算 N下账期计算
        }

        // 折扣月租金
        if (this.haveYZJ) {
          let arr2 = [this.rentDiscount4PriceDay] //阶梯租金的日租金
          let arr3 = [this.rentDiscount4PriceMonth] //阶梯租金的月租金
          this.copyRentLadderArr.map(item => {
            arr2.push(item.disD)
            arr3.push(item.disM)
          })
          data.contract.rent_increse_discount_day = arr2 + ''
          data.contract.rent_increse_discount_month = arr3 + ''
        }

        let expenses = []
        this.costItem.map(item => {
          if (item.expense_type == 'P' || item.expense_type == 'O' || item.expense_type == 'T') {
            expenses.push({
              "name": item.expense_name + '',
              "period": item.expense_period || '0',
              "amount": Number(item.amount).toFixed(4) || '0',
              "price": item.price || '0',
              "priceDay": item.priceDayCopy || '0',
              "priceMonth": item.priceMonthCopy || '0',
              "late_fee_percent": item.late_fee / 100 + '' || '0',
              "expense_type": item.expense_type,
              "custom_period": item.customPeriod.length ? JSON.parse(JSON.stringify(item.customPeriod)) : '#',
              "units_code": item.unitsCode.length ? item.unitsCode + '' : '#',
              "payment_date_config": '#',
              "commission_date_boa": '#',
              "commission_date_fix_type": '#',
              "commission_date_fix_num": this.billDate.naturalDay + '',
              "tax_percent": item.tax_percent ? (item.tax_percent / 100 + '') : '#',
              "expense_date": item.expense_type == 'O' ? item.end_date : '#',
              "expense_memo": item.memo || '#'
            })
          }
        })
        if (this.haveGDflag && this.isGDZJflag) {
          expenses.push({
            "name": '固定租金',
            "period": '0',
            "amount": '0',
            "price": this.oPrice,
            "priceDay": this.dRent,
            "priceMonth": this.mRent,
            "late_fee_percent": this.rentBill.rentPercent ? this.rentBill.rentPercent / 100 + '' : '0', //押金滞纳金比列
            "expense_type": 'R',
            "custom_period": '#',
            "units_code": "#",
            "tax_percent": '#'
          })
        }
        if (this.haveYJflag && this.isYJflag) {
          expenses.push({
            "name": '押金',
            "period": this.rentBill.bet + '',
            "amount": this.yaTotal + '',
            "price": '0',
            "priceDay": '0',
            "priceMonth": '0',
            "late_fee_percent": this.rentBill.proportion ? this.rentBill.proportion / 100 + '' : '0', //押金滞纳金比列
            "expense_type": 'D',
            "custom_period": '#',
            "units_code": "#",
            "tax_percent": '#'
          })
        }
        if (this.haveYYECCflag && this.isYYECCflag) {
          expenses.push({
            "name": '营业额抽成',
            "period": this.paymentCycle + '',
            "amount": '0',
            "price": '0',
            "priceDay": '0',
            "priceMonth": '0',
            "late_fee_percent": '0',
            "expense_type": 'CM',
            "custom_period": '#',
            "units_code": "#",
            "payment_date_config": this.paymentTypeCode + '' || '#',
            "commission_date_boa": this.billDateQHcode + '' || '#',
            "commission_date_fix_type": this.billDaycode + '' || '#',
            "commission_date_fix_num": this.paymentTypeCode == 'BL' ? this.billDate.naturalDay + '' : this.dayNum + '',
            "tax_percent": '#'
          })
        }

        var lastStepData = JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_FIRST_STEP'))

        if (lastStepData && lastStepData.intent) {
          if (lastStepData.intent.intentDeductibleAmount) {
            this.intentDeductibleAmount = -Number(lastStepData.intent.intentDeductibleAmount)
          }
        }

        if (expenses.length < 1) {
          hl.toast('至少填写一个费项')
          return
        }
        data.expenses = expenses
        this.payplanData = data
      },

      changeaaaa(obj, list) {
				this.not_update_info_list = list;
        obj.expense_list.map(item => {
          item.expense_late_fee = '0'
          if (item.expense_type == 'P') {
            item.amount_reveice = '0.00'
          }
          if (item.expense_type == 'R') {
            item.amount_reveice = '#'
            item.expense_late_fee = '#'
            item.tax_percent = '#'
          }
        })

        this.putPlayData()
        let eData = JSON.parse(JSON.stringify(this.payplanData.contract))

        // delete eData.first_payment_date
        planDataList.push(obj)
        console.log(planDataList)
        hlhttp.post({
          url: 'bill_plans/_update',
          data: {
            contract: JSON.stringify(eData),
            expenses: JSON.stringify(this.payplanData.expenses),
            update_info_list: JSON.stringify(planDataList),
						not_update_info_list: JSON.stringify(this.not_update_info_list)
          },
          success: (data) => {
            this.ePayData = data
          }
        })
        // this.ePayData
      },
      //选择文档类型
      selectedTemType(item) {
        let index = this.selectedTemTypeList.indexOf(item)
        if (index > -1) {
          this.selectedTemTypeList.splice(index, 1)
        } else {
          this.selectedTemTypeList.push(item)
        }
      },
      //选择文档
      selectedTem(item) {
        this.selectedTemList = item.id
      },
      //新增合同模板
      addNewTem() {
        hlUrlUtil.goTo('billTemplate', {
          ddtab: true
        }, true)
      },
      //合同预览/打印
      previewTemPrint() {
        this.TemplateModulShow = true
        var that = this
        hlhttp.get({
          url: 'contract/print_templates',
          success: function (data) {
            that.temList = data
          }
        })
      },
      //导出合同模板
      exportTemplate() {
        if (!this.selectedTemTypeList.length) {
          hl.toast('请选择文件类型')
          return
        }
        if (!this.selectedTemList) {
          hl.toast('请选择模板')
          return
        }
        this.saveContract(4)
      },
      //预览合同模板
      preview(id) {
        this.saveContract(3, id)
      },
      previewImage: function (url) {
        var imageExt = ['jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'];
        var pdfExt = ['pdf', 'PDF'];
        var officeExt = ['docx', 'doc', 'xlsx', 'xls', 'xlt'];
        var imageFlag = false;
        var pdfFlag = false;
        var officeFlag = false;

        imageExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) imageFlag = true;
        })

        if (imageFlag) {
          $.imageShow([url])
          return
        }
        pdfExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) pdfFlag = true;
        })
        if (pdfFlag) {
          $.previewPDF(url)
          return
        }

        officeExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) officeFlag = true
        })
        if (officeFlag) {
          $.previewOffice(url)
          return
        }
        hl.toast('暂不支持该格式')
      },
      downloadFiles(fileUrls) {
        fileUrls.forEach(v => {
          this.createIFrame(v);
        })
      },
      createIFrame(url) {
        setTimeout(() => {
          let frame = document.createElement('iframe');
          frame.style = 'display: none;';
          frame.class = 'multi-download';
          frame.src = url,

            document.body.appendChild(frame);
          setTimeout(function () {
            document.body.removeChild(frame);
          }, 1000);

        })
      },
      // 校验是否规则（新增、提交，保存什么的）
      // 1:租赁时间
      isRequiredDate() {
        if (!this.endDate) {
          hl.toast('请选择租赁期限')
          return false
        }
        return true
      },
      // 2:固定租金
      isRequiredGDZJ() {
        if (!this.oPrice) {
          hl.toast('请输入租金单价')
          return false
        }
        if (!this.dRent) {
          hl.toast('请输入日租金')
          return false
        }
        if (!this.mRent) {
          hl.toast('请输入月租金')
          return false
        }
        if (!this.rentBill.pay) {
          hl.toast('请输入付款周期')
          return false
        }
        return true
      },
      // 3:押金
      isRequiredYJ() {
        this.rentBill.bet = this.rentBill.bet + ''
        this.rentBill.menoy = this.rentBill.menoy + ''
        if (!this.rentBill.bet) {
          hl.toast('请输入押付方式')
          return false
        }
        if (!this.rentBill.menoy) {
          hl.toast('请输入押付金额')
          return false
        }
        return true
      },
      // 4：阶梯租金
      isRequiredJTZJ() {
        let flag = true
        this.rentLadder.some(item => {
          if (!item.lv || !item.dj || !item.rz || !item.yz) {
            flag = false;
          }
          // 折扣月租金
          if (this.haveYZJ) {
            if (!item.dis || !item.disD || !item.disM) {
              flag = false;
            }
          }
        })
        if (!flag) {
          hl.toast('请输入阶梯租金')
        }
        return flag
      },
      // 5：免租金
      isRequiredMZQ() {
        let flag = true
        this.freePeriod.some(item => {
          if (!item.btime || !item.etime) {
            flag = false;
          }
        })
        if (!flag) {
          hl.toast('请输入免租期')
        }
        return flag
      },
      // 6：营业额抽成
      isRequiredYYECC() {
        if (!this.paymentCycle) {
          hl.toast('请输入营业额付款周期')
          return false

        }
        if (this.paymentTypeCode + '' == 'CM') {
          if (!this.dayNum) {
            hl.toast('请输入自然日')
            return false
          }
        }
        let arr = this.tableArr

        for (let n = 0; n < arr.length; n++) {
          if (n == 0 && arr.length > 1) {
            if (!arr[n].commission_percent || !arr[n].base_val_up_limit) {
              hl.toast('请完成营业额表单')
              return false
            }
          }
          if (n > 0 || arr.length == 1) {
            if (!arr[n].commission_percent) {
              hl.toast('请完成营业额表单')
              return false
            }
          }
        }
        return true
      },
      // 7：费项是否填写完整(一次性，周期性，临时，押金费项)
      isCompleteFX() {
        let arr = this.costItem
        for (var i = 0; i < arr.length; i++) {
          if (arr[i].expense_type == 'D') {
            if (!arr[i].expense_name || !arr[i].price || !arr[i].expense_period || !arr[i].amount) {
              hl.toast('请完成押金费项')
              return false
            }
          }
          if (arr[i].expense_type == 'P') {
            if (!arr[i].expense_name || !arr[i].priceDay || !arr[i].priceMonth || !arr[i].expense_period || !arr[i].late_fee) {
              hl.toast('请完成周期性费项')
              return false
            }
          }
          if (arr[i].expense_type == 'O') {
            if (!arr[i].expense_name || !arr[i].amount || !arr[i].late_fee) {
              hl.toast('请完成一次性费项')
              return false
            }
          }
          if (arr[i].expense_type == 'T') {
            if (!arr[i].expense_name || !arr[i].amount || !arr[i].tax_percent) {
              hl.toast('请完成临时费项')
              return false
            }
          }
        }
        return true
      }
    },
    created() {
      let cache = JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_SECOND_STEP'))

      if (cache) {
        Object.assign(this.$data, cache)
        this.$data.isPayBillFlag = false
        this.$data.getCtPrevData = JSON.parse(window.sessionStorage.getItem('CREATED_CONTRACT_FIRST_STEP'))
      } else {
        if (this.contractId) {
          this.getContractDetail()
          this.getCtData()
          this.getYZJconfig()
        } else {
          this.beginDate = hlDateUtil.formatUTCDate((new Date()).getTime(), 'yyyy-MM-dd')
          this.SQdate = hlDateUtil.formatUTCDate((new Date()).getTime(), 'yyyy-MM-dd')
          this.signingDate = hlDateUtil.formatUTCDate((new Date()).getTime(), 'yyyy-MM-dd')
          this.getCostItem()
          this.getCtData()
          this.getYZJconfig()
          this.getCommission()
        }
      }
    },
    mounted() {
      this.getSelfRent()
      this.ladderRentConfig()
      this.getTurnoverArr()
      this.yzunitwp()
      this.get_CM_EXPENDITURE_UNIT()
      this.getBreakPrice()
      this.isYXDKflag() //获取意向抵扣
    },
  })
}())
